home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Framework / Sources / UView.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  143.2 KB  |  4,991 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UView.cp
  3. // Copyright © 1987-96 by Apple Computer, Inc. All rights reserved.
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #ifndef __UVIEW__
  7. #include "UView.h"
  8. #endif
  9.  
  10. // MacApp
  11.  
  12. #ifndef __UBEHAVIOR__
  13. #include "UBehavior.h"
  14. #endif
  15.  
  16. #ifndef __UCLIPBOARDMGR__
  17. #include "UClipboardMgr.h"
  18. #endif
  19.  
  20. #ifndef __UCOMMAND__
  21. #include "UCommand.h"
  22. #endif
  23.  
  24. #ifndef __UCOREGLOBALS__
  25. #include "UCoreGlobals.h"
  26. #endif
  27.  
  28. #ifndef __UCOREUTILITIES__
  29. #include "UCoreUtilities.h"
  30. #endif
  31.  
  32. #ifndef __UDEBUG__
  33. #include "UDebug.h"
  34. #endif
  35.  
  36. #ifndef __UDEPENDENCIES__
  37. #include "UDependencies.h"
  38. #endif
  39.  
  40. #ifndef __UDISPATCHER__
  41. #include "UDispatcher.h"
  42. #endif
  43.  
  44. #ifndef __UDOCUMENT__
  45. #include "UDocument.h"
  46. #endif
  47.  
  48. #ifndef __UDRAG__
  49. #include "UDragDrop.h"
  50. #endif
  51.  
  52. #ifndef __UDRAWINGENVIRONMENT__
  53. #include "UDrawingEnvironment.h"
  54. #endif
  55.  
  56. #ifndef __UFAILURE__
  57. #include "UFailure.h"
  58. #endif
  59.  
  60. #ifndef __UGEOMETRY__
  61. #include "UGeometry.h"
  62. #endif
  63.  
  64. #ifndef __ULIST__
  65. #include "UList.h"
  66. #endif
  67.  
  68. #ifndef __UMACAPPGLOBALS__
  69. #include "UMacAppGlobals.h"
  70. #endif
  71.  
  72. #ifndef __UMACAPPUTILITIES__
  73. #include "UMacAppUtilities.h"
  74. #endif
  75.  
  76. #ifndef __UMEMORY__
  77. #include "UMemory.h"
  78. #endif
  79.  
  80. #ifndef __UPATCH__
  81. #include "UPatch.h"
  82. #endif
  83.  
  84. #ifndef __UPRINTHANDLER__
  85. #include "UPrintHandler.h"
  86. #endif
  87.  
  88. #ifndef __USCROLLER__
  89. #include "UScroller.h"
  90. #endif
  91.  
  92. #ifndef __USTREAM__
  93. #include "UStream.h"
  94. #endif
  95.  
  96. #ifndef __UVIEWSERVER__
  97. #include "UViewServer.h"
  98. #endif
  99.  
  100. #ifndef __UWINDOW__
  101. #include "UWindow.h"
  102. #endif
  103.  
  104. // Toolbox
  105.  
  106. #ifndef __DIALOGS__
  107. #include <Dialogs.h>
  108. #endif
  109.  
  110. #ifndef __EDITIONS__
  111. #include <Editions.h>
  112. #endif
  113.  
  114. #ifndef __ERRORS__
  115. #include <Errors.h>
  116. #endif
  117.  
  118. #if qGXViews || qGXPrinting
  119. #    ifndef __GXGRAPHICS__
  120. #    include <GXGraphics.h>
  121. #    endif
  122. #endif
  123.  
  124. #ifndef __LOWMEM__
  125. #include <LowMem.h>
  126. #endif
  127.  
  128. #ifndef __RESOURCES__
  129. #include <Resources.h>
  130. #endif
  131.  
  132. #ifndef __SCRAP__
  133. #include <Scrap.h>
  134. #endif
  135.  
  136. #ifndef __TOOLUTILS__
  137. #include <ToolUtils.h>
  138. #endif
  139.  
  140. // ANSI
  141.  
  142. #ifndef __STDIO__
  143. #include <stdio.h>
  144. #endif
  145.  
  146. //========================================================================================
  147. // static data members
  148. //========================================================================================
  149. TView* TView::gFocusedView;
  150. Boolean TView::gDrawingPictScrap;
  151. TView* TView::gDrawingPictScrapView;
  152. Boolean TView::gPrinting;
  153.  
  154. #if qGXViews || qGXPrinting
  155. gxGraphicsClient TView::gGXGraphicsClient;
  156. #endif
  157.  
  158. //========================================================================================
  159. // CLASS CSubViewIterator
  160. //========================================================================================
  161. #undef Inherited
  162. #define Inherited CIterator
  163.  
  164. //----------------------------------------------------------------------------------------
  165. // CSubViewIterator::CSubViewIterator: 
  166. //----------------------------------------------------------------------------------------
  167. #pragma segment MAViewRes
  168.  
  169. CSubViewIterator::CSubViewIterator(const TView* theSuperView,
  170.                                    Boolean itsForward) :
  171.     fFirstView(theSuperView ? theSuperView->fSubView : NULL),
  172.     fIterateForward(itsForward)
  173. {
  174.     Reset();
  175. }
  176.  
  177. //----------------------------------------------------------------------------------------
  178. // CSubViewIterator::Reset: 
  179. //----------------------------------------------------------------------------------------
  180. #pragma segment MAViewRes
  181.  
  182. void CSubViewIterator::Reset()
  183. {
  184.     fCurrentSubView = fIterateForward ? FirstView() : LastView();
  185. }
  186.  
  187. //----------------------------------------------------------------------------------------
  188. // CSubViewIterator::Advance: 
  189. //----------------------------------------------------------------------------------------
  190. #pragma segment MAViewRes
  191.  
  192. TView* CSubViewIterator::FirstSubView()
  193. {
  194.     Reset();
  195.     return fCurrentSubView;                        // Always return the first View
  196. }
  197.  
  198. //----------------------------------------------------------------------------------------
  199. // CSubViewIterator::Advance: 
  200. //----------------------------------------------------------------------------------------
  201. #pragma segment MAViewRes
  202.  
  203. TView* CSubViewIterator::NextSubView()
  204. {
  205.     Advance();
  206.     return fCurrentSubView;
  207. }
  208.  
  209. //----------------------------------------------------------------------------------------
  210. // CSubViewIterator::Advance: 
  211. //----------------------------------------------------------------------------------------
  212. #pragma segment MAViewRes
  213.  
  214. void CSubViewIterator::Advance()
  215. {
  216.     if (fCurrentSubView)
  217.         fCurrentSubView = fIterateForward ? NextView(fCurrentSubView) : PreviousView(fCurrentSubView);
  218. }
  219.  
  220. //----------------------------------------------------------------------------------------
  221. // CSubViewIterator::PreviousView: 
  222. //----------------------------------------------------------------------------------------
  223. #pragma segment MAViewRes
  224. TView* CSubViewIterator::PreviousView(TView* aView) const
  225. {
  226.     TView * currentView = FirstView();
  227.     while (currentView && (NextView(currentView) != aView))
  228.         currentView = NextView(currentView);
  229.  
  230.     return currentView;
  231. }
  232.  
  233.  
  234. //----------------------------------------------------------------------------------------
  235. // CSubViewIterator::LastView: 
  236. //----------------------------------------------------------------------------------------
  237. #pragma segment MAViewRes
  238. TView* CSubViewIterator::LastView() const
  239. {
  240.     TView * currentView = FirstView();
  241.     while (currentView && NextView(currentView))
  242.         currentView = NextView(currentView);
  243.  
  244.     return currentView;
  245. }
  246.  
  247. //========================================================================================
  248. // CLASS TView
  249. //========================================================================================
  250. #undef Inherited
  251. #define Inherited TCommandHandler
  252.  
  253. #pragma segment MAOpen
  254. MA_DEFINE_CLASS_M1(TView,
  255.                    Inherited);
  256.  
  257. //----------------------------------------------------------------------------------------
  258. // TView constructor
  259. //----------------------------------------------------------------------------------------
  260. #pragma segment MAOpen
  261.  
  262. TView::TView() :
  263.     fLocation(gZeroVPt),
  264.     fSize(gZeroVPt),
  265.     fTranslation(gZeroVPt),
  266.     fViewToQDOffset(gZeroVPt),
  267.     fVisibleExtent(gZeroVRect),
  268.     fQDOrigin(gZeroPt),
  269.     fSuperView(NULL),
  270.     fSubView(NULL),
  271.     fNextView(NULL),
  272.     fDocument(NULL),
  273.     fDrawingEnvironment(NULL),
  274.     fAdorners(NULL),
  275.     fUserArea(0),
  276.     fTemplateVersion(kMAThreeOhTemplateVersion),
  277.     fHelpIndex(1),
  278.     fHelpID(kNoResource),
  279.     fCursorID(kNoResource),
  280.     fActiveHL(hlOn),
  281.     fInactiveHL(hlDim),
  282.     fHandlesCursor(TRUE),
  283.     fLetsSubViewsHandleCursor(TRUE),
  284.     fHandlesHelp(TRUE),
  285.     fHandlesFirstClicks(TRUE),
  286.     fLetsSubViewsHandleHelp(TRUE),
  287.     fShown(TRUE),
  288.     fWantsToBeTarget(FALSE),
  289.     fCoordinatesAreInvalid(TRUE)
  290. #if qDrag
  291.     ,
  292.     fDraggable(FALSE),
  293.     fDroppable(FALSE),
  294.     fDragMoveDeterminer(kNeverMove),
  295.     fDragMoveFamily(kNoIdentifier)
  296. #endif // qDrag
  297. {
  298.     fSizeDeterminer[hSel] = sizeVariable;
  299.     fSizeDeterminer[vSel] = sizeVariable;
  300. }
  301.  
  302. //----------------------------------------------------------------------------------------
  303. // TView::IView: 
  304. //----------------------------------------------------------------------------------------
  305. #pragma segment MAOpen
  306.  
  307. void TView::IView(TDocument* itsDocument,
  308.                   TView* itsSuperView,
  309.                   const VPoint& itsLocation,
  310.                   const VPoint& itsSize,
  311.                   SizeDeterminer itsHSizeDet,
  312.                   SizeDeterminer itsVSizeDet)
  313. {
  314.     ICommandHandler(itsSuperView);
  315.  
  316.     // fSuperView = itsSuperView; set below in AddSubView's call to BeInSuperView.
  317.     fLocation = itsLocation;
  318.     fSize = itsSize;
  319.     fSizeDeterminer[hSel] = itsHSizeDet;
  320.     fSizeDeterminer[vSel] = itsVSizeDet;
  321.  
  322.     FailInfo fi;
  323.     Try(fi)
  324.     {
  325.         if (itsSuperView)
  326.             itsSuperView->AddSubView(this);
  327.         BeInDocument(itsDocument);
  328.         fi.Success();
  329.     }
  330.     else                                        // Recover
  331.     {
  332.         Free();
  333.         fi.ReSignal();
  334.     }
  335. }
  336.  
  337. //----------------------------------------------------------------------------------------
  338. // TView::HandlePostCreate: 
  339. //----------------------------------------------------------------------------------------
  340. #pragma segment MAOpen
  341.  
  342. void TView::HandlePostCreate(TDocument* itsDocument)
  343. {
  344.     if (!fDocument)
  345.         BeInDocument(itsDocument);
  346. #if qDebugMsg
  347.     else if (fDocument && !IsObject(fDocument))
  348.         ProgramBreak("###Unknown fDocument in TView::HandlePostCreate.");
  349. #endif
  350.  
  351.     if (HasSubViews())
  352.     {
  353.         CSubViewIterator iter(this);
  354.  
  355.         for (TView * aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
  356.             aView->HandlePostCreate(itsDocument);
  357.     }
  358.  
  359.     TBehavior * aBehavior = GetFirstEnabledBehavior();
  360.     if (aBehavior)
  361.         aBehavior->DoPostCreate(itsDocument);
  362.  
  363.     DoPostCreate(itsDocument);
  364. }
  365.  
  366. //----------------------------------------------------------------------------------------
  367. // TView::DoPostCreate: 
  368. //----------------------------------------------------------------------------------------
  369. #pragma segment MAOpen
  370.  
  371. void TView::DoPostCreate(TDocument*                /* itsDocument */ )
  372. {
  373. #if qDrag
  374.     if (fDroppable && HasDragManager())            // if this view receives drops, register it with its window
  375.     {
  376.         TWindow * itsWindow = GetWindow();
  377.         if (itsWindow)
  378.             itsWindow->RegisterDroppableView(this);
  379.     }
  380. #endif // qDrag
  381.  
  382. }
  383.  
  384. //----------------------------------------------------------------------------------------
  385. // TView::Clone: 
  386. //----------------------------------------------------------------------------------------
  387. #pragma segment MAViewNonRes
  388.  
  389. TObject* TView::Clone()                            // override 
  390. {
  391.     MAVolatileInit(TView * , aClonedView, (TView *)Inherited::Clone());
  392.  
  393.     aClonedView->fSuperView = NULL;
  394.     aClonedView->fSubView = NULL;
  395.     aClonedView->fNextView = NULL;
  396.     aClonedView->fDrawingEnvironment = NULL;
  397.     aClonedView->fAdorners = NULL;
  398.     aClonedView->fNextHandler = NULL;
  399.     aClonedView->fDocument = NULL;
  400.  
  401.     FailInfo fi;
  402.     Try(fi)
  403.     {
  404.         // Extra block needed for correct ordering of failure handlers
  405.         if (HasSubViews())
  406.         {
  407.             CSubViewIterator iter(this);
  408.  
  409.             for (TView * aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
  410.             {
  411.                 TView * aClonedSubView = (TView *)aView->Clone();
  412.  
  413.                 FailInfo innerfi;
  414.                 Try(innerfi)
  415.                 {
  416.                     aClonedView->AddSubView(aClonedSubView);
  417.                     innerfi.Success();
  418.                 }
  419.                 else
  420.                 {
  421.                     aClonedSubView->Free();
  422.                     innerfi.ReSignal();
  423.                 }
  424.             }
  425.         }
  426.  
  427.         if (fDrawingEnvironment)
  428.             aClonedView->fDrawingEnvironment = (TDrawingEnvironment *)fDrawingEnvironment->Clone();
  429.  
  430.         // Extra block needed for correct ordering of failure handlers
  431.         {
  432.             CAdornerIterator iter(this);
  433.  
  434.             for (TAdorner * anAdorner = iter.FirstAdorner(); iter.More(); anAdorner = iter.NextAdorner())
  435.             {
  436.                 AdornPriority itsPriority = fAdorners->PriorityAt(iter.CurrentIndex());
  437.  
  438.                 if (anAdorner->fFreeOnDeletion)    // If its not shared…
  439.                 {
  440.                     TAdorner * aClonedAdorner = (TAdorner *)anAdorner->Clone();
  441.                     aClonedView->AddAdorner(aClonedAdorner, itsPriority, FALSE);
  442.                 }
  443.                 else
  444.                     aClonedView->AddAdorner(anAdorner, itsPriority, FALSE);
  445.             }
  446.         }
  447.         fi.Success();
  448.     }
  449.     else                                        // Recover
  450.     {
  451.         aClonedView->Free();
  452.         fi.ReSignal();
  453.     }
  454.  
  455.     return aClonedView;
  456. }
  457.  
  458. //----------------------------------------------------------------------------------------
  459. // TView::Free: 
  460. //----------------------------------------------------------------------------------------
  461. #pragma segment MAClose
  462.  
  463. TView::~TView()
  464. {
  465.     while (fSubView)
  466.         fSubView->Free();
  467.  
  468.     InvalidateFocus();
  469.     gDispatcher->InvalidateMouseRegions();        // Must re-calc cursor and help rgn.
  470.  
  471.     if (this == gDispatcher->GetTarget())        // Fixup the target chain 
  472.         gDispatcher->SetTarget(gDispatcher);
  473.  
  474.     if (fSuperView)
  475.     {
  476.         fSuperView->RemoveSubView(this);
  477.         fSuperView = NULL;                        // redundant, but safe
  478.     }
  479.  
  480.     fDrawingEnvironment = (TDrawingEnvironment *)FreeIfObject(fDrawingEnvironment);
  481.  
  482.     if (fAdorners)
  483.     {
  484.         CAdornerIterator iter(this);
  485.  
  486.         for (TAdorner * theAdorner = iter.FirstAdorner(); iter.More(); theAdorner = iter.NextAdorner())
  487.             theAdorner->RemovedFromView(this);    // theAdorner might get freed here 
  488.     }
  489.     fAdorners = (TAdornerList *)FreeIfObject(fAdorners);
  490.  
  491.     if (fDocument)
  492.     {
  493.         fDocument->DeleteView(this);
  494.         fDocument = NULL;
  495.     }
  496. }
  497.  
  498. //----------------------------------------------------------------------------------------
  499. // TView::HighlightAdorners: 
  500. //----------------------------------------------------------------------------------------
  501. #pragma segment MAActivate
  502.  
  503. void TView::HighlightAdorners(const VRect& area,
  504.                               HLState fromHL,
  505.                               HLState toHL)
  506. {
  507.     PenState savePenState;
  508.     HLState localFromHL = fromHL;
  509.     HLState localToHL = toHL;
  510.  
  511.     // The direction of iteration is controlled by the following state transition diagram:
  512.     //
  513.     // toHL
  514.     //                   ||     OFF       ||           DIM          ||       ON
  515.     //  --------------||-------------||-------------------||-------------------
  516.     //          OFF      ||     (NA)     ||         Forward       ||     Forward
  517.     //  --------------||-------------||-------------------||-------------------
  518.     //  fromHL  DIM      ||   Backward     ||          (NA)          ||     Forward
  519.     //  --------------||-------------||-------------------||-------------------
  520.     //          ON      ||   Backward     ||        Backward      ||      (NA)
  521.     //  --------------||-------------||-------------------||-------------------
  522.  
  523.     PenNormal();
  524.     GetPenState(&savePenState);
  525.  
  526.     if (((fromHL == hlOn) && ((toHL == hlDim) || (toHL == hlOff))) || ((fromHL == hlDim) && (toHL == hlOff)))
  527.     {
  528.         CAdornerIterator iter(this, kIterateBackward);
  529.  
  530.         for (TAdorner * anAdorner = iter.FirstAdorner(); iter.More(); anAdorner = iter.NextAdorner())
  531.         {
  532.             if (anAdorner->DoesAdorn(this))
  533.             {
  534.                 SetPenState(&savePenState);
  535.                 anAdorner->DoHighlightSelection(this, area, localFromHL, localToHL);
  536.             }
  537.         }
  538.     }
  539.     else if ((((fromHL == hlOff) || (fromHL == hlDim)) && (toHL == hlOn)) || ((fromHL == hlOff) && (toHL == hlDim)))
  540.     {
  541.         CAdornerIterator iter(this);
  542.  
  543.         for (TAdorner * anAdorner = iter.FirstAdorner(); iter.More(); anAdorner = iter.NextAdorner())
  544.         {
  545.             if (anAdorner->DoesAdorn(this))
  546.             {
  547.                 SetPenState(&savePenState);
  548.                 anAdorner->DoHighlightSelection(this, area, localFromHL, localToHL);
  549.             }
  550.         }
  551.     }
  552. }
  553.  
  554. //----------------------------------------------------------------------------------------
  555. // TView::Activate: 
  556. //----------------------------------------------------------------------------------------
  557. #pragma segment MAActivate
  558.  
  559. void TView::Activate(Boolean entering)
  560. {
  561.     if (fAdorners && IsDrawable())
  562.     {
  563.         VRect visRect(GetDrawableRect());
  564.         if (entering)
  565.             HighlightAdorners(visRect, fInactiveHL, fActiveHL);
  566.         else
  567.             HighlightAdorners(visRect, fActiveHL, fInactiveHL);
  568.     }
  569.  
  570.     if (HasSubViews())
  571.     {
  572.         CSubViewIterator iter(this);
  573.  
  574.         for (TView * aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
  575.             aView->Activate(entering);
  576.     }
  577. }
  578.  
  579. //----------------------------------------------------------------------------------------
  580. // TView::AddAdorner: 
  581. //----------------------------------------------------------------------------------------
  582. #pragma segment MAViewNonRes
  583.  
  584. void TView::AddAdorner(TAdorner* anAdorner,
  585.                        AdornPriority itsPriority,
  586.                        Boolean invalidate)
  587. {
  588.     Boolean oldObjectPerm = AllocateObjectsFromPerm(FALSE);
  589.     fAdorners = MakeAdornerList();
  590.     fAdorners->AddAdorner(anAdorner, itsPriority);
  591.     AllocateObjectsFromPerm(oldObjectPerm);
  592.  
  593.     anAdorner->AddedToView(this);
  594.  
  595.     if (invalidate)
  596.         anAdorner->InvalidateAdorner(this);
  597. }
  598.  
  599. //----------------------------------------------------------------------------------------
  600. // TView::DeleteAdorner: 
  601. //----------------------------------------------------------------------------------------
  602. #pragma segment MAViewNonRes
  603.  
  604. void TView::DeleteAdorner(TAdorner* anAdorner,
  605.                           Boolean invalidate)
  606. {
  607.     if (fAdorners)
  608.     {
  609.         CAdornerIterator iter(this);
  610.  
  611.         for (TAdorner * theAdorner = iter.FirstAdorner(); iter.More(); theAdorner = iter.NextAdorner())
  612.         {
  613.             if (theAdorner == anAdorner)
  614.             {
  615.                 if (invalidate)
  616.                     theAdorner->InvalidateAdorner(this);
  617.                 anAdorner->RemovedFromView(this);// anAdorner might get freed here 
  618.                 fAdorners->DeleteElementsAt(iter.fCurrentIndex, 1);
  619.             }
  620.         }
  621.  
  622.         // dispose of fAdorners if it only contains the default gDrawAdorner 
  623.         if ((fAdorners->GetSize() == 1) && (AdornerAt(1) == gDrawAdorner))
  624.             fAdorners = (TAdornerList *)(FreeIfObject(fAdorners));
  625.     }
  626. }
  627.  
  628. //----------------------------------------------------------------------------------------
  629. // TView::DeleteAdornerByID: 
  630. //----------------------------------------------------------------------------------------
  631. #pragma segment MAViewNonRes
  632.  
  633. void TView::DeleteAdornerByID(IDType itsID,
  634.                               Boolean invalidate)
  635. {
  636.     if (fAdorners)
  637.     {
  638.         CAdornerIterator iter(this);
  639.  
  640.         for (TAdorner * theAdorner = iter.FirstAdorner(); iter.More(); theAdorner = iter.NextAdorner())
  641.         {
  642.             if (theAdorner->fIdentifier == itsID)
  643.             {
  644.                 if (invalidate)
  645.                     theAdorner->InvalidateAdorner(this);
  646.                 theAdorner->RemovedFromView(this);// anAdorner might get freed here 
  647.                 fAdorners->DeleteElementsAt(iter.fCurrentIndex, 1);
  648.             }
  649.         }
  650.  
  651.         // dispose of fAdorners if it only contains the default gDrawAdorner 
  652.         if ((fAdorners->GetSize() == 1) && (AdornerAt(1) == gDrawAdorner))
  653.             fAdorners = (TAdornerList *)(FreeIfObject(fAdorners));
  654.     }
  655. }
  656.  
  657. //----------------------------------------------------------------------------------------
  658. // TView::AdornerAt: 
  659. //----------------------------------------------------------------------------------------
  660. #pragma segment MAViewRes
  661.  
  662. TAdorner* TView::AdornerAt(ArrayIndex i) const
  663. {
  664.     return fAdorners ? fAdorners->AdornerAt(i) : NULL;
  665. }
  666.  
  667. //----------------------------------------------------------------------------------------
  668. // TView::AdornerWithID: 
  669. //----------------------------------------------------------------------------------------
  670. #pragma segment MAViewRes
  671.  
  672. TAdorner* TView::AdornerWithID(IDType itsID) const
  673. {
  674.     TAdorner* returnVal = NULL;
  675.  
  676.     if (fAdorners)
  677.     {
  678.         CAdornerIterator iter(this);
  679.  
  680.         for (TAdorner * theAdorner = iter.FirstAdorner(); iter.More(); theAdorner = iter.NextAdorner())
  681.             if (theAdorner->fIdentifier == itsID)
  682.             {
  683.                 returnVal = theAdorner;
  684.                 break;
  685.             }
  686.     }
  687.  
  688.     return returnVal;
  689. }
  690.  
  691. //----------------------------------------------------------------------------------------
  692. // TView::Dim: 
  693. //----------------------------------------------------------------------------------------
  694. #pragma segment MAViewRes
  695.  
  696. void TView::Dim()
  697. {
  698. #if qDebug
  699.     AssumeFocused();
  700. #endif
  701.  
  702.     PenPat(&qd.gray);
  703.     PenMode(patBic);
  704.     PaintRect(&GetQDExtent());
  705. }
  706.  
  707. //----------------------------------------------------------------------------------------
  708. // TView::GetAdornExtent: 
  709. //----------------------------------------------------------------------------------------
  710. #pragma segment MAViewRes
  711.  
  712. void TView::GetAdornExtent(VRect& itsAdornExtent)
  713. {
  714.     itsAdornExtent = GetExtent();
  715. }
  716.  
  717. //----------------------------------------------------------------------------------------
  718. // TView::GetEventNumber: 
  719. //----------------------------------------------------------------------------------------
  720. #pragma segment MAViewRes
  721.  
  722. EventNumber TView::GetEventNumber()
  723. {
  724.     return cNoEvent;
  725. }
  726.  
  727. //----------------------------------------------------------------------------------------
  728. // TView::Hilite: 
  729. //----------------------------------------------------------------------------------------
  730. #pragma segment MAViewRes
  731.  
  732. void TView::Hilite()
  733. {
  734. #if qDebug
  735.     AssumeFocused();
  736. #endif
  737.  
  738.     InvertRect(&GetQDExtent());
  739. }
  740.  
  741. //----------------------------------------------------------------------------------------
  742. // TView::MakeAdornerList: 
  743. //----------------------------------------------------------------------------------------
  744. #pragma segment MAViewNonRes
  745.  
  746. TAdornerList* TView::MakeAdornerList()
  747. {
  748.     if (fAdorners)
  749.         return fAdorners;
  750.     else
  751.     {
  752.         MAVolatileInit(TAdornerList * , anAdornerList, new TAdornerList);
  753.         anAdornerList->IAdornerList();
  754.  
  755.         FailInfo fi;
  756.         Try(fi)
  757.         {
  758.             anAdornerList->AddAdorner(gDrawAdorner, kDrawView);// default "Draw" adorner 
  759.             fi.Success();
  760.         }
  761.         else                                    // Recover
  762.         {
  763.             anAdornerList->Free();
  764.             fi.ReSignal();
  765.         }
  766.  
  767.         return anAdornerList;
  768.     }
  769. }
  770.  
  771. //----------------------------------------------------------------------------------------
  772. // TView::InsertSubView: 
  773. //----------------------------------------------------------------------------------------
  774. #pragma segment MAOpen
  775.  
  776. void TView::InsertSubView(TView* theSubView,
  777.                           Boolean last)
  778. {
  779. #if qDebug
  780.     FailNonObject(theSubView);
  781. #endif
  782.  
  783.     if (last && fSubView)
  784.     {
  785.         // place at the tail of the list
  786.         register TView* lastView = fSubView;
  787.         register TView* nextView = lastView->fNextView;
  788.         while (nextView)
  789.         {
  790.             lastView = nextView;
  791.             nextView = lastView->fNextView;
  792.         }
  793.         lastView->fNextView = theSubView;
  794.         theSubView->fNextView = NULL;
  795.     }
  796.     else                                        // first
  797.     {
  798.         theSubView->fNextView = fSubView;
  799.         fSubView = theSubView;
  800.     }
  801. }
  802.  
  803. //----------------------------------------------------------------------------------------
  804. // TView::DeleteSubView: 
  805. //----------------------------------------------------------------------------------------
  806. #pragma segment MAViewNonRes
  807.  
  808. void TView::DeleteSubView(TView* theSubView)
  809. {
  810. #if qDebug
  811.     FailNonObject(theSubView);
  812. #endif
  813.  
  814.     if (fSubView)
  815.     {
  816.         if (fSubView == theSubView)
  817.             fSubView = theSubView->fNextView;
  818.         else
  819.         {
  820.             register TView* lastView = fSubView;
  821.             register TView* nextView = fSubView->fNextView;
  822.             while (nextView && (nextView != theSubView))
  823.             {
  824.                 lastView = nextView;
  825.                 nextView = lastView->fNextView;
  826.             }
  827.  
  828.             if (nextView)
  829.                 lastView->fNextView = theSubView->fNextView;
  830.             else
  831.             {
  832. #if qDebug
  833.                 ProgramBreak("Delete subview not in list!");
  834. #endif
  835.  
  836.             }
  837.         }
  838.  
  839.         theSubView->fNextView = NULL;
  840.     }
  841.  
  842. }
  843.  
  844. //----------------------------------------------------------------------------------------
  845. // TView::AddedASubView: 
  846. //----------------------------------------------------------------------------------------
  847. #pragma segment MAOpen
  848.  
  849. void TView::AddedASubView(TView* newSubView)
  850. {
  851.     if (fSuperView)
  852.         fSuperView->AddedASubView(newSubView);
  853. }
  854.  
  855. //----------------------------------------------------------------------------------------
  856. // TView::AddSubView: 
  857. //----------------------------------------------------------------------------------------
  858. #pragma segment MAOpen
  859.  
  860. void TView::AddSubView(TView* theSubView)
  861. {
  862.     if (theSubView)
  863.     {
  864.         InsertSubView(theSubView);
  865.  
  866.         theSubView->BeInSuperView(this);
  867.         AddedASubView(theSubView);
  868.     }
  869. }
  870.  
  871. //----------------------------------------------------------------------------------------
  872. // TView::AdjustFrame: 
  873. //----------------------------------------------------------------------------------------
  874. #pragma segment MAViewRes
  875.  
  876. void TView::AdjustFrame()
  877. {
  878.     VRect oldFrame(GetFrame());
  879.     VRect newFrame(oldFrame);
  880.     ComputeFrame(newFrame);
  881.  
  882.     if (newFrame != oldFrame)
  883.     {
  884.         SetFrame(newFrame, kInvalidate);
  885.         DoPagination();
  886.     }
  887.     else if (HasSubViews())
  888.     {
  889.         CSubViewIterator iter(this);
  890.  
  891.         for (TView * aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
  892.             aView->AdjustFrame();
  893.     }
  894. }
  895.  
  896. //----------------------------------------------------------------------------------------
  897. // TView::AssumeFocused: 
  898. //----------------------------------------------------------------------------------------
  899. #if qDebug
  900. #pragma segment MADebug
  901.  
  902. void TView::AssumeFocused() const
  903. {
  904.     if (gAssumeFocused)
  905.         if (!IsFocused())
  906.         {
  907. #if qDebugMsg
  908.             fprintf(stderr, ", ClassName=%s\n", GetClassName());
  909.             if (gFocusedView)
  910.             {
  911.                 fprintf(stderr, "View actually focused is:\n");
  912.                 fprintf(stderr, ", ClassName=%s\n", gFocusedView->GetClassName());
  913.             }
  914. #endif
  915.             ProgramBreak("Failed AssumeFocused");
  916.         }
  917. }
  918. #endif
  919.  
  920. //----------------------------------------------------------------------------------------
  921. // TView::AttachPrintHandler: 
  922. //----------------------------------------------------------------------------------------
  923. #pragma segment MAViewNonRes
  924.  
  925. void TView::AttachPrintHandler(TPrintHandler* itsPrintHandler)
  926. {
  927.     AddAdorner(gPrintAdorner, kAdornLast, FALSE);// adorner calls DoDrawPrintFeedback 
  928.     AddBehavior(itsPrintHandler);
  929.     DoCheckPrinter();
  930. }
  931.  
  932. //----------------------------------------------------------------------------------------
  933. // TView::DetachPrintHandler: 
  934. //----------------------------------------------------------------------------------------
  935. #pragma segment MAViewNonRes
  936.  
  937. void TView::DetachPrintHandler(TPrintHandler* itsPrintHandler)
  938. {
  939.     DeleteAdorner(gPrintAdorner, FALSE);
  940.     RemoveBehavior(itsPrintHandler);
  941.     DoCheckPrinter();
  942. }
  943.  
  944. //----------------------------------------------------------------------------------------
  945. // TView::GetPrintHandler: 
  946. //----------------------------------------------------------------------------------------
  947. #pragma segment MAViewRes
  948.  
  949. TPrintHandler* TView::GetPrintHandler()
  950. {
  951.     return (TPrintHandler *)GetBehaviorWithIdentifier(kPrintBehaviorID);
  952. }
  953.  
  954. //----------------------------------------------------------------------------------------
  955. // TView::BeInPort: 
  956. //----------------------------------------------------------------------------------------
  957. #pragma segment MAViewNonRes
  958.  
  959. void TView::BeInPort(GrafPtr itsPort)
  960. {
  961.     if (itsPort && GetPrintHandler())
  962.         DoCheckPrinter();
  963.  
  964.     if (HasSubViews())
  965.     {
  966.         CSubViewIterator iter(this);
  967.  
  968.         for (TView * aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
  969.             aView->BeInPort(itsPort);
  970.     }
  971.  
  972.     InvalidateCoordinates();
  973. }
  974.  
  975. //----------------------------------------------------------------------------------------
  976. // TView::BeInDocument: 
  977. //----------------------------------------------------------------------------------------
  978. #pragma segment MAOpen
  979.  
  980. void TView::BeInDocument(TDocument* itsDocument)
  981. {
  982.     if (itsDocument && (itsDocument != fDocument))
  983.     {
  984.         fDocument = itsDocument;
  985.         fDocument->AddView(this);
  986.     }
  987. }
  988.  
  989. //----------------------------------------------------------------------------------------
  990. // TView::BeInScroller: 
  991. //----------------------------------------------------------------------------------------
  992. #pragma segment MAOpen
  993.  
  994. void TView::BeInScroller(TScroller* itsScroller)
  995. {
  996.     // convert the size to superview location.
  997.  
  998.     if (itsScroller)
  999.         itsScroller->SetScrollLimits(fSize + fLocation, kDontRedraw);
  1000. }
  1001.  
  1002. //----------------------------------------------------------------------------------------
  1003. // TView::BeInSuperView: 
  1004. //----------------------------------------------------------------------------------------
  1005. #pragma segment MAOpen
  1006.  
  1007. void TView::BeInSuperView(TView* itsSuperview)
  1008. {
  1009.     if (fSuperView != itsSuperview)
  1010.     {
  1011.         TView * oldSuperView = fSuperView;
  1012.  
  1013.         fSuperView = itsSuperview;
  1014.         InvalidateFocus();                        // the subview may have been focused 
  1015.  
  1016.         if (itsSuperview)
  1017.         {
  1018.             if (!fNextHandler)                    // If necessary, 
  1019.                 fNextHandler = itsSuperview;    // …hook this view up to an event hander chain.
  1020.             BeInPort(GetGrafPort());
  1021.         }
  1022.         else
  1023.         {
  1024.             // Removing this view from its superview 
  1025.             if (fNextHandler == oldSuperView)    // If next event handler is the former superview
  1026.                 fNextHandler = NULL;            // take this view out of the event handler chain.
  1027.             BeInPort(NULL);
  1028.         }
  1029.     }
  1030. }
  1031.  
  1032. //----------------------------------------------------------------------------------------
  1033. // TView::FindTarget: 
  1034. //----------------------------------------------------------------------------------------
  1035. #pragma segment MAViewRes
  1036.  
  1037. TView* TView::FindTarget()
  1038. {
  1039.     TView * foundView = NULL;
  1040.  
  1041.     if (WantsToBeTarget())
  1042.         foundView = this;
  1043.     else if (HasSubViews())
  1044.     {
  1045.         CSubViewIterator iter(this);
  1046.  
  1047.         for (TView * aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
  1048.         {
  1049.             foundView = aView->FindTarget();
  1050.             if (foundView)
  1051.                 break;
  1052.         }
  1053.     }
  1054.  
  1055.     return foundView;
  1056. }
  1057.  
  1058. //----------------------------------------------------------------------------------------
  1059. // TView::SetTargetSelection: 
  1060. //----------------------------------------------------------------------------------------
  1061. #pragma segment MAViewRes
  1062.  
  1063. void TView::SetTargetSelection(Boolean redraw)
  1064. {
  1065.     ScrollSelectionIntoView(redraw);
  1066. }
  1067.  
  1068. //----------------------------------------------------------------------------------------
  1069. // TView::WantsToBeTarget: 
  1070. //----------------------------------------------------------------------------------------
  1071. #pragma segment MAViewRes
  1072.  
  1073. Boolean TView::WantsToBeTarget()                // Override
  1074.  
  1075. {
  1076.     return fWantsToBeTarget;
  1077. }
  1078.  
  1079. //----------------------------------------------------------------------------------------
  1080. // TView::ContainsSubView: 
  1081. //----------------------------------------------------------------------------------------
  1082. #pragma segment MAViewRes
  1083.  
  1084. Boolean TView::ContainsSubView(TView* aSubView) const
  1085. {
  1086.     Boolean foundView = FALSE;
  1087.  
  1088.     if (HasSubViews())
  1089.     {
  1090.         for (TView * viewToTest = aSubView; viewToTest; viewToTest = viewToTest->fSuperView)
  1091.         {
  1092.             if (viewToTest->fSuperView == this)
  1093.             {
  1094.                 foundView = TRUE;
  1095.                 break;
  1096.             }
  1097.         }
  1098.     }
  1099.  
  1100.     return foundView;
  1101. }
  1102.  
  1103.  
  1104. //----------------------------------------------------------------------------------------
  1105. // TView::CalcMinFrame: 
  1106. //----------------------------------------------------------------------------------------
  1107. #pragma segment MAViewRes
  1108.  
  1109. VRect TView::CalcMinFrame()
  1110. {
  1111.     return GetFrame();
  1112. }
  1113.  
  1114. //----------------------------------------------------------------------------------------
  1115. // TView::ClipFurtherTo: 
  1116. //----------------------------------------------------------------------------------------
  1117. #pragma segment MAViewRes
  1118.  
  1119. void TView::ClipFurtherTo(RgnHandle rRgn,
  1120.                           CPoint deltaOrg)
  1121. {
  1122. #if qDebug
  1123.     AssumeFocused();
  1124. #endif
  1125.  
  1126.     SectRgn(GetClipRegion(qd.thePort), rRgn, rRgn);
  1127.     if (deltaOrg != gZeroPt)
  1128.         OffsetRgn(rRgn, deltaOrg.h, deltaOrg.v);
  1129.     SetClip(rRgn);
  1130. }
  1131.  
  1132. //----------------------------------------------------------------------------------------
  1133. // TView::OffsetAndClipFurtherTo: 
  1134. //----------------------------------------------------------------------------------------
  1135. #pragma segment MAViewRes
  1136.  
  1137. void TView::OffsetAndClipFurtherTo(RgnHandle rRgn,
  1138.                                    CPoint deltaOrg)
  1139. {
  1140. #if qDebug
  1141.     AssumeFocused();
  1142. #endif
  1143.  
  1144.     // First offset the clip Rgn 
  1145.     if (deltaOrg != gZeroPt)
  1146.         OffsetRgn(GetClipRegion(qd.thePort), deltaOrg.h, deltaOrg.v);
  1147.  
  1148.     SectRgn(GetClipRegion(qd.thePort), rRgn, rRgn);
  1149.     SetClip(rRgn);
  1150. }
  1151.  
  1152. //----------------------------------------------------------------------------------------
  1153. // TView::Close: 
  1154. //----------------------------------------------------------------------------------------
  1155. #pragma segment MAClose
  1156.  
  1157. void TView::Close()
  1158. {
  1159.     Changed(mClosed, this);
  1160.  
  1161.     if (HasSubViews())
  1162.     {
  1163.         CSubViewIterator iter(this);
  1164.  
  1165.         for (TView * aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
  1166.             aView->Close();
  1167.     }
  1168. }
  1169.  
  1170. //----------------------------------------------------------------------------------------
  1171. // TView::ComputeFrame: 
  1172. //----------------------------------------------------------------------------------------
  1173. #pragma segment MAViewRes
  1174.  
  1175. void TView::ComputeFrame(VRect& newFrame)
  1176. {
  1177.     VRect minFrame;                                // will be calculated only when necessary
  1178.     Boolean haveMinFrame = FALSE;
  1179.  
  1180.     // Adjust view size based on size determiners. 
  1181.     for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
  1182.     {
  1183.         VCoordinate dimension;
  1184.  
  1185.         switch (fSizeDeterminer[vhs])
  1186.         {
  1187.             case sizeFixed:
  1188.                 dimension = fSize[vhs];
  1189.                 break;
  1190.  
  1191.             case sizeRelSuperView:
  1192.                 dimension = newFrame.GetSize()[vhs];// newFrame set in
  1193.                 // SuperViewChangedSize
  1194.                 break;
  1195.  
  1196.             case sizeSuperView:
  1197.                 if (fSuperView)
  1198.                     dimension = fSuperView->fSize[vhs];
  1199.                 else
  1200.                 {
  1201.                     if (!haveMinFrame)
  1202.                     {
  1203.                         minFrame = CalcMinFrame();
  1204.                         haveMinFrame = TRUE;
  1205.                     }
  1206.                     dimension = minFrame.GetSize()[vhs];// Set dimension to a default
  1207.                 }
  1208.                 break;
  1209.  
  1210.             case sizePage:
  1211.                 {
  1212.                     // If there is no printhandler we can defer until one is attached 
  1213.                     TPrintHandler * itsPrintHandler = GetPrintHandler();
  1214.                     if (itsPrintHandler)
  1215.                         dimension = itsPrintHandler->GetViewPerPage()[vhs];
  1216.                     else
  1217.                     {
  1218.                         if (!haveMinFrame)
  1219.                         {
  1220.                             minFrame = CalcMinFrame();
  1221.                             haveMinFrame = TRUE;
  1222.                         }
  1223.                         dimension = minFrame.GetSize()[vhs];// Set dimension to a default
  1224.                     }
  1225.                 }
  1226.                 break;
  1227.  
  1228.             case sizeFillPages:
  1229.                 {
  1230.                     if (!haveMinFrame)
  1231.                     {
  1232.                         minFrame = CalcMinFrame();
  1233.                         haveMinFrame = TRUE;
  1234.                     }
  1235.                     // If there is no printhandler we can defer until one is attached 
  1236.                     TPrintHandler * itsPrintHandler = GetPrintHandler();
  1237.                     if (itsPrintHandler)
  1238.                         dimension = RoundUp(minFrame.GetSize()[vhs], (short)(itsPrintHandler->GetViewPerPage()[vhs]));
  1239.                     else
  1240.                         dimension = minFrame.GetSize()[vhs];// Set dimension to a default
  1241.                 }
  1242.                 break;
  1243.  
  1244.             case sizeVariable:                    // For sizeVariable dimension is already set correctly
  1245.             default:
  1246.                 if (!haveMinFrame)
  1247.                 {
  1248.                     minFrame = CalcMinFrame();
  1249.                     haveMinFrame = TRUE;
  1250.                 }
  1251.                 dimension = minFrame.GetSize()[vhs];// Set dimension to a default 
  1252.                 break;
  1253.         }
  1254.         newFrame[botRight][vhs] = newFrame[topLeft][vhs] + dimension;
  1255.     }
  1256. }
  1257.  
  1258. //----------------------------------------------------------------------------------------
  1259. // TView::ContainsClipType: 
  1260. //----------------------------------------------------------------------------------------
  1261. #pragma segment MAViewRes
  1262.  
  1263. Boolean TView::ContainsClipType(ResType aType)
  1264. {
  1265.     long offset;
  1266.  
  1267.     return (GetScrap(NULL, aType, &offset) > 0);
  1268. }
  1269.  
  1270. //----------------------------------------------------------------------------------------
  1271. // TView::ContainsMouse: 
  1272. //----------------------------------------------------------------------------------------
  1273. #pragma segment MAViewRes
  1274.  
  1275. Boolean TView::ContainsMouse(const VPoint& theMouse)
  1276. {
  1277.     CTemporaryRegion extentRgn;
  1278.     GetExtentRegion(extentRgn);
  1279.  
  1280.     return (IsShown() && PtInRgn(ViewToQDPt(theMouse), extentRgn));
  1281. }
  1282.  
  1283. //----------------------------------------------------------------------------------------
  1284. // TView::CountSubViews: 
  1285. //----------------------------------------------------------------------------------------
  1286. #pragma segment MAViewRes
  1287.  
  1288. short TView::CountSubViews() const
  1289. {
  1290.     short count = 0;
  1291.  
  1292.     register TView* subView = fSubView;
  1293.     while (subView)
  1294.     {
  1295.         ++count;
  1296.         subView = subView->fNextView;
  1297.     }
  1298.  
  1299.     return count;
  1300. }
  1301.  
  1302. //----------------------------------------------------------------------------------------
  1303. // TView::DoBreakFollowing: 
  1304. //----------------------------------------------------------------------------------------
  1305. #pragma segment MAPrint
  1306.  
  1307. VCoordinate TView::DoBreakFollowing(VHSelect vhs,
  1308.                                     VCoordinate previousBreak,
  1309.                                     Boolean& automatic)
  1310. {
  1311.     VCoordinate returnVal = 0;
  1312.  
  1313.     TPrintHandler * itsPrintHandler = GetPrintHandler();
  1314.     if (itsPrintHandler)
  1315.         returnVal = itsPrintHandler->BreakFollowing(vhs, previousBreak, automatic);
  1316.  
  1317.     return returnVal;
  1318. }
  1319.  
  1320. //----------------------------------------------------------------------------------------
  1321. // TView::DoCalcPageStrips: 
  1322. //----------------------------------------------------------------------------------------
  1323. #pragma segment MAPrint
  1324.  
  1325. VPoint TView::DoCalcPageStrips()
  1326. {
  1327.     TPrintHandler * itsPrintHandler = GetPrintHandler();
  1328.     
  1329.     return itsPrintHandler ? itsPrintHandler->CalcPageStrips() : gZeroVPt;
  1330. }
  1331.  
  1332. //----------------------------------------------------------------------------------------
  1333. // TView::DoCalcViewPerPage: 
  1334. //----------------------------------------------------------------------------------------
  1335. #pragma segment MAPrint
  1336.  
  1337. VPoint TView::DoCalcViewPerPage()
  1338. {
  1339.     TPrintHandler * itsPrintHandler = GetPrintHandler();
  1340.  
  1341.     return itsPrintHandler ? itsPrintHandler->CalcViewPerPage() : fSize;
  1342. }
  1343.  
  1344. //----------------------------------------------------------------------------------------
  1345. // TView::DoCheckPrinter: 
  1346. //----------------------------------------------------------------------------------------
  1347. #pragma segment MAViewNonRes
  1348.  
  1349. void TView::DoCheckPrinter()
  1350. {
  1351.     // If you are sizeVariable and are going to want to depend on the printed page geometry
  1352.     // then you will want to override this method and add an appropriate test
  1353.  
  1354.     TPrintHandler * itsPrintHandler = GetPrintHandler();
  1355.     if (itsPrintHandler)
  1356.     {
  1357.         if (itsPrintHandler->fShowBreaks || fSizeDeterminer[vSel] == sizePage || fSizeDeterminer[vSel] == sizeFillPages || fSizeDeterminer[hSel] == sizePage || fSizeDeterminer[hSel] == sizeFillPages)
  1358.             itsPrintHandler->Update();
  1359.     }
  1360. }
  1361.  
  1362. //----------------------------------------------------------------------------------------
  1363. // TView::DoDrawPrintFeedback: 
  1364. //----------------------------------------------------------------------------------------
  1365. #pragma segment MAViewRes
  1366.  
  1367. void TView::DoDrawPrintFeedback(const VRect& area)
  1368. {
  1369. #if qDebug
  1370.     AssumeFocused();
  1371. #endif
  1372.  
  1373.     TPrintHandler * itsPrintHandler = GetPrintHandler();
  1374.     if (itsPrintHandler)
  1375.         itsPrintHandler->DrawPrintFeedback(area);
  1376. }
  1377.  
  1378. //----------------------------------------------------------------------------------------
  1379. // TView::DoDrawPageBreak: 
  1380. //----------------------------------------------------------------------------------------
  1381. #pragma segment MAPrint
  1382.  
  1383. void TView::DoDrawPageBreak(VHSelect vhs,
  1384.                             short whichBreak,
  1385.                             VCoordinate loc,
  1386.                             Boolean automatic)
  1387. {
  1388.     TPrintHandler * itsPrintHandler = GetPrintHandler();
  1389.     if (itsPrintHandler)
  1390.         itsPrintHandler->DrawPageBreak(vhs, whichBreak, loc, automatic);
  1391. }
  1392.  
  1393. //----------------------------------------------------------------------------------------
  1394. // TView::HandlesCursor: 
  1395. //----------------------------------------------------------------------------------------
  1396. #pragma segment MAViewRes
  1397.  
  1398. Boolean TView::HandlesCursor()
  1399. {
  1400.     Boolean result = (fHandlesCursor && IsEnabled()) || LetsSubViewsHandleCursor()
  1401. #if qDrag
  1402.     ||fDraggable
  1403. #endif
  1404.     ;
  1405.  
  1406.     return result;
  1407. }
  1408.  
  1409. //----------------------------------------------------------------------------------------
  1410. // TView::LetsSubViewsHandleCursor: 
  1411. //----------------------------------------------------------------------------------------
  1412. #pragma segment MAViewRes
  1413.  
  1414. Boolean TView::LetsSubViewsHandleCursor()
  1415. {
  1416.     return fLetsSubViewsHandleCursor && HasSubViews();
  1417. }
  1418.  
  1419. //----------------------------------------------------------------------------------------
  1420. // TView::HandlesHelp: 
  1421. //----------------------------------------------------------------------------------------
  1422. #pragma segment MAViewRes
  1423.  
  1424. Boolean TView::HandlesHelp()
  1425. {
  1426.     return fHandlesHelp || LetsSubViewsHandleHelp();
  1427. }
  1428.  
  1429. //----------------------------------------------------------------------------------------
  1430. // TView::LetsSubViewsHandleHelp: 
  1431. //----------------------------------------------------------------------------------------
  1432. #pragma segment MAViewRes
  1433.  
  1434. Boolean TView::LetsSubViewsHandleHelp()
  1435. {
  1436.     return fLetsSubViewsHandleHelp && HasSubViews();
  1437. }
  1438.  
  1439. //----------------------------------------------------------------------------------------
  1440. // TView::UpdateSelection: 
  1441. //----------------------------------------------------------------------------------------
  1442. #pragma segment MAViewRes
  1443.  
  1444. void TView::UpdateSelection(const VPoint&        /* theMouse */ ,
  1445.                             TToolboxEvent*        /* event */ )
  1446. {
  1447. }
  1448.  
  1449. //----------------------------------------------------------------------------------------
  1450. // TView::DoHighlightSelection: 
  1451. //----------------------------------------------------------------------------------------
  1452. #pragma segment MAViewRes
  1453.  
  1454. void TView::DoHighlightSelection(HLState        /* fromHL */,
  1455.                                  HLState        /* toHL */)
  1456. {
  1457. }
  1458.  
  1459. //----------------------------------------------------------------------------------------
  1460. // TView::GetCurrentHL: 
  1461. //----------------------------------------------------------------------------------------
  1462. #pragma segment MAViewRes
  1463.  
  1464. HLState TView::GetCurrentHL()
  1465. {
  1466.     return IsActive() ? fActiveHL : fInactiveHL;
  1467. }
  1468.  
  1469. //----------------------------------------------------------------------------------------
  1470. // TView::DoMouseCommand: 
  1471. //----------------------------------------------------------------------------------------
  1472. #pragma segment MASelCommand
  1473.  
  1474. void TView::DoMouseCommand(VPoint&                /* theMouse */ ,
  1475.                            TToolboxEvent*        /* event */ ,
  1476.                            CPoint                /* hysteresis */)
  1477. {
  1478. }
  1479.  
  1480. //----------------------------------------------------------------------------------------
  1481. // TView::DoMouseUp: 
  1482. //----------------------------------------------------------------------------------------
  1483. #pragma segment MASelCommand
  1484.  
  1485. void TView::DoMouseUp(VPoint&                    /* theMouse */ ,
  1486.                       TToolboxEvent*            /* event */ ,
  1487.                       CPoint                    /* hysteresis */)
  1488. {
  1489. }
  1490.  
  1491. //----------------------------------------------------------------------------------------
  1492. // TView::DoPagination: 
  1493. //----------------------------------------------------------------------------------------
  1494. #pragma segment MAViewNonRes
  1495.  
  1496. void TView::DoPagination()
  1497. {
  1498.     TPrintHandler * itsPrintHandler = GetPrintHandler();
  1499.     if (itsPrintHandler)
  1500.         itsPrintHandler->RedoPageBreaks();
  1501. }
  1502.  
  1503. //----------------------------------------------------------------------------------------
  1504. // TView::DoPrinterChanged: 
  1505. //----------------------------------------------------------------------------------------
  1506. #pragma segment MAViewNonRes
  1507.  
  1508. void TView::DoPrinterChanged()
  1509. {
  1510.     TPrintHandler * itsPrintHandler = GetPrintHandler();
  1511.     if (itsPrintHandler)
  1512.         itsPrintHandler->PrinterChanged();
  1513. }
  1514.  
  1515. //----------------------------------------------------------------------------------------
  1516. // TView::DoSetPageOffset: 
  1517. //----------------------------------------------------------------------------------------
  1518. #pragma segment MAPrint
  1519.  
  1520. void TView::DoSetPageOffset(const VPoint& coord)
  1521. {
  1522.     TPrintHandler * itsPrintHandler = GetPrintHandler();
  1523.     if (itsPrintHandler)
  1524.         itsPrintHandler->SetPageOffset(coord);
  1525. }
  1526.  
  1527. //----------------------------------------------------------------------------------------
  1528. // TView::DoSetCursor: 
  1529. //----------------------------------------------------------------------------------------
  1530. #pragma segment MAViewRes
  1531.  
  1532. void TView::DoSetCursor(const VPoint& localPoint,
  1533.                         RgnHandle cursorRegion)
  1534. {
  1535. #if qDebug
  1536.     AssumeFocused();
  1537. #endif
  1538.  
  1539. #if qDrag
  1540.     RgnHandle dragCursorRegion = NULL;
  1541.     if (HasDragManager())
  1542.     {
  1543.         if (!DoSetDragCursor(localPoint, cursorRegion, dragCursorRegion))
  1544. #endif
  1545.  
  1546.             {
  1547.                 ResNumber theCursorID = GetCursorID();
  1548.                 if (theCursorID != kNoResource)
  1549.                 {
  1550.                     CPoint localQDPoint(ViewToQDPt(localPoint));
  1551.                     if (PtInRgn(localQDPoint, cursorRegion))
  1552.                     {
  1553.                         CursHandle aCursor = GetCursor(theCursorID);
  1554.                         FailNILResource((Handle)aCursor);
  1555.                         SetCursor(*aCursor);
  1556.                     }
  1557.                     else
  1558.                         SetCursor(&(qd.arrow));
  1559.                 }
  1560.                 else
  1561.                     SetCursor(&(qd.arrow));
  1562.  
  1563. #if qDrag
  1564.                 // remove the drag region from the cursor region so the cursor
  1565.                 // will be updated if it moves into or out of the drag region
  1566.                 if (dragCursorRegion)
  1567.                     DiffRgn(cursorRegion, dragCursorRegion, cursorRegion);
  1568. #endif
  1569.  
  1570.             }
  1571. #if qDrag
  1572.     }
  1573.     DisposeIfRgnHandle(dragCursorRegion);
  1574. #endif
  1575.  
  1576.     // If you claim the cursor don't forget to _PROPERLY_ calculate the cursorRegion or
  1577.     // WaitNextEvent might give you a lovely mouse-moved event shower. (Lather up!)
  1578.  
  1579.     // P.S. In debug this is checked for in our original caller: TApplication.TrackMouse.
  1580. }
  1581.  
  1582. //----------------------------------------------------------------------------------------
  1583. // TView::DoShowBalloon: 
  1584. //----------------------------------------------------------------------------------------
  1585. #pragma segment MAViewRes
  1586.  
  1587. void TView::DoShowBalloon(const VPoint&            /* localPoint */ ,
  1588.                           RgnHandle helpRegion,
  1589.                           const HMMessageRecord& helpMessage,
  1590.                           CPoint localQDTip,
  1591.                           const CRect&            /* localQDRect */ ,
  1592.                           short balloonVariant)
  1593. {
  1594.     LocalToGlobal(&localQDTip);
  1595.  
  1596.     OSErr err = (HMShowBalloon(&helpMessage, localQDTip, NULL, NULL, 0, balloonVariant, kHMRegularWindow));
  1597.     if (err != hmBalloonAborted)
  1598.         FailOSErr(err);
  1599.  
  1600.     // Intersect with visible region. Excludes the balloon region. 
  1601.     SectRgn(TWindow::GetVisRegion(qd.thePort), helpRegion, helpRegion);
  1602.     SectRgn(GetClipRegion(qd.thePort), helpRegion, helpRegion);
  1603. }
  1604.  
  1605. //----------------------------------------------------------------------------------------
  1606. // TView::DoShowHelp: 
  1607. //----------------------------------------------------------------------------------------
  1608. #pragma segment MAViewRes
  1609.  
  1610. void TView::DoShowHelp(const VPoint& localPoint,
  1611.                        RgnHandle helpRegion)
  1612. {
  1613.     if (GetHelpID() != kNoResource)
  1614.     {
  1615.         GetDefaultHelpRegion(localPoint, helpRegion);
  1616.  
  1617.         FailInfo fi;
  1618.         Try(fi)
  1619.         {
  1620.             HMMessageRecord helpMessage;
  1621.             CPoint tip;
  1622.             CRect hotRect;
  1623.             short balloonVariant;
  1624.  
  1625.             GetHelpParameters(localPoint, helpRegion, helpMessage, tip, hotRect, balloonVariant);
  1626.             DoShowBalloon(localPoint, helpRegion, helpMessage, tip, hotRect, balloonVariant);
  1627.             fi.Success();
  1628.         }
  1629.         else                                    // Recover
  1630.         {
  1631.             if (fi.error != hmSkippedBalloon)
  1632.                 fi.ReSignal();
  1633.  
  1634.             // fall through
  1635.         }
  1636.     }
  1637. }
  1638.  
  1639. //----------------------------------------------------------------------------------------
  1640. // TView::GetDefaultCursorRegion: 
  1641. //----------------------------------------------------------------------------------------
  1642. void TView::GetDefaultCursorRegion(const VPoint&/* localPoint */  ,
  1643.                                    RgnHandle cursorRegion)
  1644. {
  1645.     // If we get all the way to this view without any other view having claimed the cursor
  1646.     // its because no superview handled it in a "HandleCursor" and no subview handled it
  1647.     // in a "DoSetCursor" thus there is a _very_ high probability that this view should
  1648.     // set the cursor. Just in case though, we remove the frames.
  1649.     //
  1650.     // If a containing view wishes to set the cursor for itself && all its subview, the
  1651.     // place to do that is in our caller: HandleCursor. See HandleCursor in the homebrew
  1652.     // controls TDialogView subclass in DemoDialogs.
  1653.     //
  1654.     // This strategy lets MacApp provide the _largest_ possible cursor rgn, as a default.
  1655.     // This way windows, controls, background views, etc can have nice big cursor rgns but
  1656.     // the developer can wrest control if they care to.
  1657.  
  1658.     static const short kRgnHandleTooBig = 16 * 1024;// regions > 16K don't work too well
  1659.  
  1660. #if qDebug
  1661.     AssumeFocused();
  1662. #endif
  1663.  
  1664.     GetExtentRegion(cursorRegion);
  1665.  
  1666.     // We won't claim subviews' territory
  1667.     if (LetsSubViewsHandleCursor())
  1668.     {
  1669.         Boolean rgnHandleWasTooBig = FALSE;
  1670.         CTemporaryRegion subViewFrameRgn;
  1671.         CSubViewIterator iter(this);
  1672.  
  1673.         for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  1674.         {
  1675.             if (theSubView->HandlesCursor() && !rgnHandleWasTooBig)
  1676.             {
  1677.                 theSubView->GetExtentRegion(subViewFrameRgn);// Remember, the frame is in OUR
  1678.                 // coordinate system
  1679.                 theSubView->LocalToSuperRegion(subViewFrameRgn);
  1680.                 DiffRgn(cursorRegion, subViewFrameRgn, cursorRegion);// Remove the subview from the claimed rgn 
  1681.  
  1682.                 if ((GetHandleSize((Handle)cursorRegion) > kRgnHandleTooBig) || (MemError() != noErr))
  1683.                 {
  1684.                     rgnHandleWasTooBig = TRUE;
  1685.                     SetEmptyRgn(cursorRegion);
  1686.                 }
  1687.             }
  1688.         }
  1689.     }
  1690.     // If you claim the cursor don't forget to _PROPERLY_ calculate the cursorRegion or
  1691.     // WaitNextEvent might give you a lovely mouse-moved event shower. (Lather up!)
  1692.  
  1693.     // P.S. In debug this is checked for in our original caller: TApplication.TrackCursor.
  1694. }
  1695.  
  1696. //----------------------------------------------------------------------------------------
  1697. // TView::GetDefaultHelpRegion: 
  1698. //----------------------------------------------------------------------------------------
  1699. void TView::GetDefaultHelpRegion(const VPoint&    /* localPoint */ ,
  1700.                                  RgnHandle helpRegion)
  1701. {
  1702.     static const short kRgnHandleTooBig = 16 * 1024;// regions > 16K don't work too well
  1703.  
  1704. #if qDebug
  1705.     AssumeFocused();
  1706. #endif
  1707.  
  1708.     GetExtentRegion(helpRegion);
  1709.  
  1710.     // We won't claim subviews' territory 
  1711.     if (LetsSubViewsHandleHelp())
  1712.     {
  1713.         Boolean rgnHandleWasTooBig = FALSE;
  1714.         CTemporaryRegion subViewFrameRgn;
  1715.         CSubViewIterator iter(this);
  1716.  
  1717.         for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  1718.         {
  1719.             if (theSubView->HandlesHelp() && !rgnHandleWasTooBig)
  1720.             {
  1721.                 theSubView->GetExtentRegion(subViewFrameRgn);// Remember, the frame is in OUR
  1722.                 // coordinate system
  1723.                 theSubView->LocalToSuperRegion(subViewFrameRgn);
  1724.                 DiffRgn(helpRegion, subViewFrameRgn, helpRegion);// Remove the subview from the claimed rgn 
  1725.  
  1726.                 if ((GetHandleSize((Handle)helpRegion) > kRgnHandleTooBig) || (MemError() != noErr))
  1727.                 {
  1728.                     rgnHandleWasTooBig = TRUE;
  1729.                     SetEmptyRgn(helpRegion);
  1730.                 }
  1731.             }
  1732.         }
  1733.     }
  1734. }
  1735.  
  1736. //----------------------------------------------------------------------------------------
  1737. // TView::GetLocalOffsetInSuper: 
  1738. //----------------------------------------------------------------------------------------
  1739. #pragma segment MAViewRes
  1740.  
  1741. VPoint TView::GetLocalOffsetInSuper() const
  1742. {
  1743.     return fLocation - fTranslation;
  1744. }
  1745.  
  1746. //----------------------------------------------------------------------------------------
  1747. // TView::SetLocalOrigin: 
  1748. //----------------------------------------------------------------------------------------
  1749. #pragma segment MAViewRes
  1750.  
  1751. void TView::SetLocalOrigin(const VPoint& newOrigin,
  1752.                            Boolean redraw)
  1753. {
  1754.     if (fTranslation != -newOrigin)
  1755.     {
  1756.         fTranslation = -newOrigin;
  1757.         InvalidateFocus();
  1758.         InvalidateCoordinates();
  1759.         if (redraw)
  1760.             ForceRedraw();
  1761.     }
  1762. }
  1763.  
  1764. //----------------------------------------------------------------------------------------
  1765. // TView::GetUserSelection: 
  1766. //----------------------------------------------------------------------------------------
  1767. #pragma segment MAViewRes
  1768.  
  1769. TDesignator* TView::GetUserSelection()
  1770. {
  1771.     return fSuperView ? fSuperView->GetUserSelection() : fDocument->GetUserSelection();
  1772. }
  1773.  
  1774. //----------------------------------------------------------------------------------------
  1775. // TView::SetUserSelection: 
  1776. //----------------------------------------------------------------------------------------
  1777. #pragma segment MAViewRes
  1778.  
  1779. void TView::SetUserSelection(TDesignator* newSelection)
  1780. {
  1781.     if (fSuperView)
  1782.         fSuperView->SetUserSelection(newSelection);
  1783.     else if (fDocument)
  1784.         fDocument->SetUserSelection(newSelection);
  1785. }
  1786.  
  1787. //----------------------------------------------------------------------------------------
  1788. // TView::UserSelectionChanged: 
  1789. //----------------------------------------------------------------------------------------
  1790. #pragma segment MAViewRes
  1791.  
  1792. void TView::UserSelectionChanged(TView* changedView)
  1793. {
  1794.     if (fSuperView)
  1795.         fSuperView->UserSelectionChanged(changedView);
  1796.     else if (fDocument)
  1797.         fDocument->UserSelectionChanged(changedView);
  1798. }
  1799.  
  1800. //----------------------------------------------------------------------------------------
  1801. // TView::ScrollSelectionIntoView: 
  1802. //----------------------------------------------------------------------------------------
  1803. #pragma segment MAScroll
  1804.  
  1805. void TView::ScrollSelectionIntoView(Boolean redraw)
  1806. {
  1807.     // As a default, reveal the view's extent
  1808.     RevealRect(GetExtent(), fSize, redraw);
  1809. }
  1810.  
  1811. //----------------------------------------------------------------------------------------
  1812. // TView::DoMakeNewDrawingEnvironment: 
  1813. //----------------------------------------------------------------------------------------
  1814. #pragma segment MAOpen
  1815.  
  1816. TDrawingEnvironment* TView::DoMakeNewDrawingEnvironment()
  1817. {
  1818.     TDrawingEnvironment * aDrawingEnvironment = new TDrawingEnvironment;
  1819.     aDrawingEnvironment->IDrawingEnvironment();
  1820.     return aDrawingEnvironment;
  1821. }
  1822.  
  1823. //----------------------------------------------------------------------------------------
  1824. // TView::CreateDrawingEnvironment: 
  1825. //----------------------------------------------------------------------------------------
  1826. #pragma segment MAOpen
  1827.  
  1828. void TView::CreateDrawingEnvironment()
  1829. {
  1830.     if (fDrawingEnvironment == NULL)
  1831.         fDrawingEnvironment = DoMakeNewDrawingEnvironment();
  1832. }
  1833.  
  1834. //----------------------------------------------------------------------------------------
  1835. // TView::SetDrawingEnvironment: 
  1836. //----------------------------------------------------------------------------------------
  1837. #pragma segment MAViewNonRes
  1838.  
  1839. void TView::SetDrawingEnvironment(TDrawingEnvironment* itsDrawingEnvironment,
  1840.                                   Boolean invalidate)
  1841. {
  1842.     // protect against installing same drawing environment
  1843.     if (fDrawingEnvironment != itsDrawingEnvironment)
  1844.     {
  1845.         fDrawingEnvironment = (TDrawingEnvironment *)FreeIfObject(fDrawingEnvironment);
  1846.         fDrawingEnvironment = itsDrawingEnvironment;
  1847.     }
  1848.     if (invalidate)
  1849.         ForceRedraw();
  1850. }
  1851.  
  1852. //----------------------------------------------------------------------------------------
  1853. // TView::PrepareForDrawing: 
  1854. //----------------------------------------------------------------------------------------
  1855. #pragma segment MAViewRes
  1856.  
  1857. void TView::PrepareForDrawing()
  1858. {
  1859.     if (fDrawingEnvironment)
  1860.         fDrawingEnvironment->Prepare();
  1861.     SetupDrawingEnvironment();
  1862. }
  1863.  
  1864. //----------------------------------------------------------------------------------------
  1865. // TView::SetupDrawingEnvironment: 
  1866. //----------------------------------------------------------------------------------------
  1867. #pragma segment MAViewRes
  1868.  
  1869. void TView::SetupDrawingEnvironment()
  1870. {
  1871.     if (fDrawingEnvironment)
  1872.         fDrawingEnvironment->Setup();
  1873. }
  1874.  
  1875. //----------------------------------------------------------------------------------------
  1876. // TView::CompleteDrawing: 
  1877. //----------------------------------------------------------------------------------------
  1878. #pragma segment MAViewRes
  1879.  
  1880. void TView::CompleteDrawing()
  1881. {
  1882.     if (fDrawingEnvironment)
  1883.         fDrawingEnvironment->Complete();
  1884. }
  1885.  
  1886. //----------------------------------------------------------------------------------------
  1887. // TView::Draw: 
  1888. //----------------------------------------------------------------------------------------
  1889. #pragma segment MAViewRes
  1890.  
  1891. void TView::Draw(const VRect&                    /* area */ )
  1892. {
  1893. }
  1894.  
  1895. //----------------------------------------------------------------------------------------
  1896. // TView::DrawContents: 
  1897. //----------------------------------------------------------------------------------------
  1898. #pragma segment MAViewRes
  1899.  
  1900. void TView::DrawContents()
  1901. {
  1902.     HandleDraw(GetExtent());
  1903. }
  1904.  
  1905. //----------------------------------------------------------------------------------------
  1906. // TView::HandleDraw: 
  1907. //----------------------------------------------------------------------------------------
  1908. #pragma segment MAViewRes
  1909.  
  1910. void TView::HandleDraw(const VRect& area)
  1911. {
  1912.     if (!(area & GetVisibleExtent()).Empty() && (IsShown()) && Focus())
  1913.     {
  1914.         // Even if the visible extent is not empty the Drawable rect might be.
  1915.         // The Focus (above) will set the clipping for us so we can use it to determine
  1916.         // what can be drawn.
  1917.         RgnHandle currentClipRgn = GetClipRegion(qd.thePort);
  1918.         CRect clipQDRect((*currentClipRgn)->rgnBBox);
  1919.         if (!clipQDRect.Empty())                // can we draw anything at all thru the current clip?
  1920.         {
  1921.             VRect drawArea(area & QDToViewRect(clipQDRect));
  1922.             if (!drawArea.Empty())                // does the requested drawing area intersect the drawable area?
  1923.             {
  1924.                 // As suggested by Ed Anson:
  1925.                 // Check to see if the drawing area intersects the clipping region
  1926.                 // before drawing.
  1927.                 CRect drawQDArea(ViewToQDRect(drawArea));
  1928.  
  1929.                 if (RectInRgn(&drawQDArea, currentClipRgn))// does the requested area intersect the drawable region?
  1930.                 {
  1931.                     PrepareForDrawing();
  1932.                     if (fAdorners)
  1933.                         DrawAdorners(drawArea);
  1934.                     else
  1935.                         Draw(drawArea);
  1936.  
  1937.                     // Give the behavior a chance to draw
  1938.                     TBehavior * aBehavior = GetFirstEnabledBehavior();
  1939.                     if (aBehavior)
  1940.                         aBehavior->Draw(drawArea);
  1941.  
  1942.                     // Draw all of the subviews
  1943.                     if (HasSubViews())
  1944.                     {
  1945.                         CSubViewIterator iter(this);
  1946.  
  1947.                         for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  1948.                         {
  1949.                             VRect subViewDrawArea(drawArea);
  1950.                             theSubView->SuperToLocalVRect(subViewDrawArea);
  1951.  
  1952.                             VRect subViewDrawAreaExtent(subViewDrawArea & theSubView->GetExtent());
  1953.                             if (!subViewDrawAreaExtent.Empty())
  1954.                                 theSubView->HandleDraw(subViewDrawAreaExtent);
  1955.                         }
  1956.                     }
  1957.  
  1958.                     // add the adornments
  1959.                     // note that we need to re-focus because we've been left focused on our subviews
  1960.                     if (!(gPrinting || gDrawingPictScrap) && fAdorners && Focus())
  1961.                         HighlightAdorners(drawArea, hlOff, GetCurrentHL());
  1962.  
  1963.                     CompleteDrawing();
  1964.                 }
  1965.             }
  1966.         }
  1967.  
  1968. #if qDebug
  1969.         if (gShowInvalidations)                    // special delay after drawing each view so you can watch it advance
  1970.         {
  1971.             long finalTicks;
  1972.             Delay(15, &finalTicks);                // so you can see it
  1973.         }
  1974. #endif
  1975.  
  1976.     }
  1977. }
  1978.  
  1979. //----------------------------------------------------------------------------------------
  1980. // TView::DrawAdorners: 
  1981. //----------------------------------------------------------------------------------------
  1982. #pragma segment MAViewRes
  1983.  
  1984. void TView::DrawAdorners(const VRect& area)
  1985. {
  1986.     PenState savePenState;
  1987.     GetPenState(&savePenState);
  1988.  
  1989.     CAdornerIterator iter(this);
  1990.     for (TAdorner * anAdorner = iter.FirstAdorner(); iter.More(); anAdorner = iter.NextAdorner())
  1991.     {
  1992.         if (anAdorner->DoesAdorn(this))
  1993.         {
  1994.             anAdorner->Draw(this, area);
  1995.             SetPenState(&savePenState);
  1996.         }
  1997.     }
  1998. }
  1999.  
  2000. //----------------------------------------------------------------------------------------
  2001. // TView::FindSubView: 
  2002. //----------------------------------------------------------------------------------------
  2003. #pragma segment MAViewRes
  2004.  
  2005. TView* TView::FindSubView(IDType itsIdentifier) const
  2006. {
  2007.     const TView* returnVal = NULL;
  2008.  
  2009.     if (fIdentifier == itsIdentifier)
  2010.         returnVal = this;
  2011.     else if (HasSubViews())
  2012.     {
  2013.         CSubViewIterator iter(this);
  2014.  
  2015.         for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  2016.         {
  2017.             if (theSubView->fIdentifier == itsIdentifier)
  2018.             {
  2019.                 returnVal = theSubView;
  2020.                 break;
  2021.             }
  2022.             else if (theSubView->fSubView)
  2023.             {
  2024.                 TView * foundSubView = theSubView->FindSubView(itsIdentifier);
  2025.                 if (foundSubView)
  2026.                 {
  2027.                     returnVal = foundSubView;
  2028.                     break;
  2029.                 }
  2030.             }
  2031.         }
  2032.     }
  2033.  
  2034.     // break const-ness
  2035.     return (TView *)returnVal;
  2036. }
  2037.  
  2038. //----------------------------------------------------------------------------------------
  2039. // TView::Focus: 
  2040. //----------------------------------------------------------------------------------------
  2041. #pragma segment MAViewRes
  2042.  
  2043. Boolean TView::Focus()
  2044. {
  2045.     Boolean returnVal = FALSE;                    // Can't focus
  2046.  
  2047.     if (IsFocused())                            // Already focused 
  2048.     {
  2049.         {
  2050. #if qDebug
  2051.         GrafPtr currentPort;
  2052.  
  2053.         GetPort(¤tPort);
  2054.         if (GetGrafPort() != currentPort)
  2055.             ProgramBreak("TView::Focus: Port is incorrect");
  2056. #endif
  2057.         }
  2058.  
  2059.         returnVal = TRUE;
  2060.     }
  2061.     else if (gDrawingPictScrapView == this)
  2062.     {
  2063.         gFocusedView = this;
  2064.  
  2065.         CRect qdExtent(GetQDExtent());
  2066.         CPoint qdOrigin(GetQDOrigin());
  2067.         SetOrigin(qdOrigin.h, qdOrigin.v);
  2068.         ClipRect(&qdExtent);
  2069.     }
  2070.     else if (FocusOnSuperView())                // do my own focus 
  2071.     {
  2072.         CPoint qdOrigin(GetQDOrigin());
  2073.         SetOrigin(qdOrigin.h, qdOrigin.v);        // set the new QD origin 
  2074.  
  2075.         CPoint deltaOrigin;
  2076.         if ((TPrintHandler::gCurrPrintHandler != NULL) && (TPrintHandler::gCurrPrintHandler->fView == this))
  2077.             deltaOrigin = qdOrigin - TPrintHandler::gCurrPrintHandler->GetQDOrigin();
  2078.         else if (fSuperView)
  2079.             deltaOrigin = qdOrigin - fSuperView->GetQDOrigin();
  2080.         else
  2081.             deltaOrigin = gZeroPt;
  2082.  
  2083.         gFocusedView = this;                    // Now we have the basic focus 
  2084.  
  2085.         // Add the shaping to the view's extent shape 
  2086.         CTemporaryRegion rRgn;
  2087.         GetExtentRegion(rRgn);
  2088.         OffsetAndClipFurtherTo(rRgn, deltaOrigin);
  2089.  
  2090.         // Add the clipping to the currently visible portion of the extent 
  2091.         GetVisibleRegion(rRgn);
  2092.         ClipFurtherTo(rRgn, gZeroPt);
  2093.  
  2094.         returnVal = TRUE;
  2095.     }
  2096.  
  2097.     return returnVal;
  2098. }
  2099.  
  2100. //----------------------------------------------------------------------------------------
  2101. // TView::FocusOnSuperView: 
  2102. //----------------------------------------------------------------------------------------
  2103. #pragma segment MAViewRes
  2104.  
  2105. Boolean TView::FocusOnSuperView()
  2106. {
  2107.     Boolean returnVal = FALSE;
  2108.  
  2109.     if (TPrintHandler::gCurrPrintHandler && (TPrintHandler::gCurrPrintHandler->fView == this))
  2110.         returnVal = TPrintHandler::gCurrPrintHandler->Focus();
  2111.     else if (fSuperView)
  2112.         returnVal = fSuperView->Focus();
  2113.  
  2114.     return returnVal;
  2115. }
  2116.  
  2117. //----------------------------------------------------------------------------------------
  2118. // TView::ForceRedraw: 
  2119. //----------------------------------------------------------------------------------------
  2120. #pragma segment MAViewRes
  2121.  
  2122. void TView::ForceRedraw()
  2123. {
  2124.     if (IsVisible())
  2125.     {
  2126.         CTemporaryRegion itsExtentRgn;
  2127.  
  2128.         GetExtentRegion(itsExtentRgn);
  2129.         InvalidateRegion(itsExtentRgn);
  2130.     }
  2131. }
  2132.  
  2133. //----------------------------------------------------------------------------------------
  2134. // TView::FreeFromClipboard: 
  2135. //----------------------------------------------------------------------------------------
  2136. #pragma segment MAClipboard
  2137.  
  2138. void TView::FreeFromClipboard()
  2139. {
  2140.     gClipboardMgr->Changed(mFreeClipboardView, this);
  2141.  
  2142.     if (fDocument)
  2143.         fDocument->FreeFromClipboard();
  2144.     else
  2145.         Free();
  2146. }
  2147.  
  2148. //----------------------------------------------------------------------------------------
  2149. // TView::GetStandardSignature: 
  2150. //----------------------------------------------------------------------------------------
  2151. #pragma segment MAWriteResource
  2152.  
  2153. IDType TView::GetStandardSignature()            // override 
  2154. {
  2155.     return kStdView;
  2156. }
  2157.  
  2158. //----------------------------------------------------------------------------------------
  2159. // TView::ReadFrom: 
  2160. //----------------------------------------------------------------------------------------
  2161. #pragma segment MAReadResource
  2162.  
  2163. void TView::ReadFrom(TStream* aStream)
  2164. {
  2165.     Inherited::ReadFrom(aStream);                // read in TEventHandler info
  2166.  
  2167.     // Subclasses of TView should override either TView::ReadFields or TView::ReadSubViews,
  2168.     // not TView::ReadFrom.
  2169.  
  2170.     ReadFields(aStream);                        // read in fields polymorphically
  2171.  
  2172.     ReadSubViews(aStream);                        // read in subviews
  2173. }
  2174.  
  2175. //----------------------------------------------------------------------------------------
  2176. // TView::ReadFields: 
  2177. //----------------------------------------------------------------------------------------
  2178. #pragma segment MAReadResource
  2179.  
  2180. void TView::ReadFields(TStream* aStream)
  2181. {
  2182.     FailInfo fi;
  2183.     Try(fi)
  2184.     {
  2185.         fTemplateVersion = aStream->ReadInteger();
  2186.  
  2187.         VPoint itsLocation;
  2188.         aStream->ReadVPoint(itsLocation);
  2189.         fLocation = itsLocation;
  2190.  
  2191.         VPoint itsSize;
  2192.         aStream->ReadVPoint(itsSize);
  2193.         fSize = itsSize;
  2194.  
  2195.         Byte itsHSizeDet, itsVSizeDet;
  2196.         // formerly SizeDeterminers; however, sizeof(enum) is compiler-dependent
  2197.         aStream->ReadBytes(&itsVSizeDet, sizeof(Byte));
  2198.         aStream->ReadBytes(&itsHSizeDet, sizeof(Byte));
  2199.         fSizeDeterminer[hSel] = (SizeDeterminer)itsHSizeDet;
  2200.         fSizeDeterminer[vSel] = (SizeDeterminer)itsVSizeDet;
  2201.  
  2202.         fShown = aStream->ReadBoolean();
  2203.         fWantsToBeTarget = aStream->ReadBoolean();
  2204.  
  2205.         fHandlesCursor = aStream->ReadBoolean();
  2206.         fLetsSubViewsHandleCursor = aStream->ReadBoolean();
  2207.         fCursorID = aStream->ReadInteger();
  2208.  
  2209.         fHandlesHelp = aStream->ReadBoolean();
  2210.         fLetsSubViewsHandleHelp = aStream->ReadBoolean();
  2211.         fHelpID = aStream->ReadInteger();
  2212.         fHelpIndex = aStream->ReadInteger();
  2213.  
  2214.         TDrawingEnvironment * aDrawingEnvironment = NULL;
  2215.         if (aStream->ReadStreamObject((TObject * &)aDrawingEnvironment))
  2216.             fDrawingEnvironment = aDrawingEnvironment;
  2217.         else
  2218.         {
  2219.             fDrawingEnvironment = NULL;
  2220. #if qDebugMsg
  2221.             ProgramBreak("###Unknown TDrawingEnvironment in TView::ReadFields.");
  2222. #endif
  2223.  
  2224.         }
  2225.  
  2226.         TAdornerList * aAdornerList = NULL;
  2227.         if (aStream->ReadStreamObject((TObject * &)aAdornerList))
  2228.             fAdorners = aAdornerList;
  2229.         else
  2230.         {
  2231.             fAdorners = NULL;
  2232. #if qDebugMsg
  2233.             ProgramBreak("###Unknown TAdornerList in TView::ReadFields.");
  2234. #endif
  2235.  
  2236.         }
  2237.  
  2238.         fUserArea = aStream->ReadLong();
  2239.  
  2240.         aStream->ReadIDType();                    // read in idtype and ignore it
  2241.         fi.Success();
  2242.     }
  2243.     else                                        // Recover
  2244.     {
  2245.         Free();
  2246.         fi.ReSignal();
  2247.     }
  2248. }
  2249.  
  2250. //----------------------------------------------------------------------------------------
  2251. // TView::ReadSubViews: 
  2252. //----------------------------------------------------------------------------------------
  2253. #pragma segment MAOpen
  2254.  
  2255. void TView::ReadSubViews(TStream* aStream)
  2256. {
  2257.     FailInfo fi;
  2258.     Try(fi)
  2259.     {
  2260.         short numSubViews = aStream->ReadInteger();// read in count of subviews
  2261.  
  2262.         for (short count = 0; count < numSubViews; ++count)
  2263.         {
  2264.             TView * aView = NULL;
  2265.  
  2266.             if (aStream->ReadStreamObject((TObject * &)aView))
  2267.                 AddSubView(aView);
  2268. #if qDebugMsg
  2269.             else
  2270.                 ProgramBreak("###Unknown TView in TView::ReadSubViews: Attempting to create a TView.");
  2271. #endif
  2272.  
  2273.         }
  2274.         fi.Success();
  2275.     }
  2276.     else                                        // Recover
  2277.     {
  2278.         Free();
  2279.         fi.ReSignal();
  2280.     }
  2281. }
  2282.  
  2283. //----------------------------------------------------------------------------------------
  2284. // TView::WriteTo: 
  2285. //----------------------------------------------------------------------------------------
  2286. #pragma segment MAWriteResource
  2287.  
  2288. void TView::WriteTo(TStream* aStream)
  2289. {
  2290.     Inherited::WriteTo(aStream);                // write out TEventHandler info
  2291.  
  2292.     // Subclasses of TView should override either TView::WriteFields or TView::WriteSubViews,
  2293.     // not TView::WriteTo.
  2294.  
  2295.     if (qWriteTemplateViews)
  2296.     {
  2297.         WriteFields(aStream);                    // write out fields polymorphically
  2298.  
  2299.         WriteSubViews(aStream);                    // write out subviews
  2300.     }
  2301. }
  2302.  
  2303. //----------------------------------------------------------------------------------------
  2304. // TView::WriteFields: 
  2305. //----------------------------------------------------------------------------------------
  2306. #pragma segment MAWriteResource
  2307.  
  2308. void TView::WriteFields(TStream* aStream)
  2309. {
  2310.     aStream->WriteInteger(fTemplateVersion);
  2311.  
  2312.     aStream->WriteVPoint(fLocation);
  2313.     aStream->WriteVPoint(fSize);
  2314.  
  2315.     Byte itsHSizeDet = (Byte)fSizeDeterminer[hSel];
  2316.     Byte itsVSizeDet = (Byte)fSizeDeterminer[vSel];
  2317.     // formerly SizeDeterminers; however, sizeof(enum) is compiler-dependent
  2318.     aStream->WriteBytes(&itsVSizeDet, sizeof(Byte));
  2319.     aStream->WriteBytes(&itsHSizeDet, sizeof(Byte));
  2320.  
  2321.     aStream->WriteBoolean(fShown);
  2322.     aStream->WriteBoolean(fWantsToBeTarget);
  2323.  
  2324.     aStream->WriteBoolean(fHandlesCursor);
  2325.     aStream->WriteBoolean(fLetsSubViewsHandleCursor);
  2326.     aStream->WriteInteger(fCursorID);
  2327.  
  2328.     aStream->WriteBoolean(fHandlesHelp);
  2329.     aStream->WriteBoolean(fLetsSubViewsHandleHelp);
  2330.     aStream->WriteInteger(fHelpID);
  2331.     aStream->WriteInteger(fHelpIndex);
  2332.  
  2333.     aStream->WriteStreamObject(fDrawingEnvironment);
  2334.  
  2335.     aStream->WriteStreamObject(fAdorners, kStandardObject);
  2336.  
  2337.     aStream->WriteLong(fUserArea);
  2338.  
  2339.     aStream->WriteIDType(GetStandardSignature());// write it out again for Rez-ability
  2340. }
  2341.  
  2342. //----------------------------------------------------------------------------------------
  2343. // TView::WriteSubViews: 
  2344. //----------------------------------------------------------------------------------------
  2345. #pragma segment MAWriteResource
  2346.  
  2347. void TView::WriteSubViews(TStream* aStream)
  2348. {
  2349.     aStream->WriteInteger(CountSubViews());        // write out count of subviews
  2350.  
  2351.     if (HasSubViews())
  2352.     {
  2353.         CSubViewIterator iter(this);
  2354.  
  2355.         for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  2356.             aStream->WriteStreamObject(theSubView, kStandardObject);
  2357.     }
  2358. }
  2359.  
  2360. //----------------------------------------------------------------------------------------
  2361. // TView::GetContext: 
  2362. //----------------------------------------------------------------------------------------
  2363. #pragma segment MAViewRes
  2364.  
  2365. TCommandHandler* TView::GetContext(CommandNumber/* aCommandNumber */ )// Override
  2366. {
  2367.     return fDocument ? fDocument : (TCommandHandler*)GetWindow();
  2368. }
  2369.  
  2370. //----------------------------------------------------------------------------------------
  2371. // TView::GetExtent: 
  2372. //----------------------------------------------------------------------------------------
  2373. #pragma segment MAViewRes
  2374.  
  2375. VRect TView::GetExtent() const
  2376. {
  2377.     // Allow for the origin of the view's coordinate system. 
  2378.     return VRect(gZeroVPt, fSize) - (GetLocalOffsetInSuper() - fLocation);
  2379. }
  2380.  
  2381. //----------------------------------------------------------------------------------------
  2382. // TView::GetExtentRegion: 
  2383. //----------------------------------------------------------------------------------------
  2384. #pragma segment MAViewRes
  2385.  
  2386. void TView::GetExtentRegion(RgnHandle itsExtentRgn)
  2387. {
  2388.     RectRgn(itsExtentRgn, &GetQDExtent());
  2389. }
  2390.  
  2391. //----------------------------------------------------------------------------------------
  2392. // TView::GetFrame: 
  2393. //----------------------------------------------------------------------------------------
  2394. #pragma segment MAViewRes
  2395.  
  2396. VRect TView::GetFrame() const
  2397. {
  2398.     return VRect(fLocation, fLocation + fSize);
  2399. }
  2400.  
  2401. //----------------------------------------------------------------------------------------
  2402. // TView::GetGrafPort: 
  2403. //----------------------------------------------------------------------------------------
  2404. #pragma segment MAViewRes
  2405.  
  2406. GrafPtr TView::GetGrafPort()
  2407. {
  2408.     GrafPtr returnVal = NULL;
  2409.  
  2410.     if (fDrawingEnvironment)
  2411.         returnVal = fDrawingEnvironment->GetGrafPort();
  2412.     if (!returnVal)
  2413.     {
  2414.         if (gPrinting || gDrawingPictScrap)
  2415.             returnVal = qd.thePort;                //thePort assumed to be set by print handler
  2416.         else if (fSuperView)
  2417.             returnVal = fSuperView->GetGrafPort();
  2418.     }
  2419.     return returnVal;
  2420. }
  2421.  
  2422. //----------------------------------------------------------------------------------------
  2423. // TView::GetPartCode: 
  2424. //----------------------------------------------------------------------------------------
  2425. #pragma segment MAViewNonRes
  2426.  
  2427. short TView::GetPartCode(const VPoint& theMouse)
  2428. {
  2429.     return GetExtent().Contains(theMouse) ? inContent : inDesk;
  2430. }
  2431.  
  2432. //----------------------------------------------------------------------------------------
  2433. // TView::GetPrintExtent: 
  2434. //----------------------------------------------------------------------------------------
  2435. #pragma segment MAViewNonRes
  2436.  
  2437. VRect TView::GetPrintExtent()
  2438. {
  2439.     return GetExtent();
  2440. }
  2441.  
  2442. //----------------------------------------------------------------------------------------
  2443. // TView::GetQDExtent: 
  2444. //----------------------------------------------------------------------------------------
  2445. #pragma segment MAViewRes
  2446.  
  2447. CRect TView::GetQDExtent()
  2448. {
  2449.     return ViewToQDRect(GetExtent());
  2450. }
  2451.  
  2452. //----------------------------------------------------------------------------------------
  2453. // TView::GetScroller: 
  2454. //----------------------------------------------------------------------------------------
  2455. #pragma segment MAViewRes
  2456.  
  2457. TScroller* TView::GetScroller(Boolean immediateSuperView)
  2458. {
  2459.     TScroller * returnVal = NULL;
  2460.  
  2461.     if (fSuperView)
  2462.     {
  2463.         TScroller * aScroller = fSuperView->GetScroller(immediateSuperView);
  2464.         if ((aScroller == fSuperView) || (!immediateSuperView))
  2465.             returnVal = aScroller;
  2466.     }
  2467.     return returnVal;
  2468. }
  2469.  
  2470. //----------------------------------------------------------------------------------------
  2471. // TView::GetVisibleRect: 
  2472. //----------------------------------------------------------------------------------------
  2473. #pragma segment MAViewRes
  2474.  
  2475. VRect TView::GetVisibleRect()
  2476. {
  2477.     return QDToViewRect(GetVisibleQDRect());
  2478. }
  2479.  
  2480. //----------------------------------------------------------------------------------------
  2481. // TView::GetVisibleQDRect: 
  2482. //----------------------------------------------------------------------------------------
  2483. #pragma segment MAViewRes
  2484.  
  2485. CRect TView::GetVisibleQDRect()
  2486. {
  2487.     CTemporaryRegion visibleRgn;
  2488.  
  2489.     GetVisibleRegion(visibleRgn);
  2490.  
  2491.     return (*(RgnHandle)visibleRgn)->rgnBBox;
  2492. }
  2493.  
  2494. //----------------------------------------------------------------------------------------
  2495. // TView::GetVisibleRegion: 
  2496. //----------------------------------------------------------------------------------------
  2497. #pragma segment MAViewRes
  2498.  
  2499. void TView::GetVisibleRegion(RgnHandle visibleRgn)
  2500. {
  2501.     VRect visibleExtent(GetVisibleExtent());
  2502.  
  2503.     if (visibleExtent.Empty())
  2504.         SetEmptyRgn(visibleRgn);
  2505.     else
  2506.     {
  2507.         RectRgn(visibleRgn, &ViewToQDRect(visibleExtent));
  2508.         VisibleRgn(visibleRgn);
  2509.     }
  2510. }
  2511.  
  2512. //----------------------------------------------------------------------------------------
  2513. // TView::GetDrawableRect: 
  2514. //----------------------------------------------------------------------------------------
  2515. #pragma segment MAViewRes
  2516.  
  2517. VRect TView::GetDrawableRect()
  2518. {
  2519.     return QDToViewRect(GetDrawableQDRect());
  2520. }
  2521.  
  2522. //----------------------------------------------------------------------------------------
  2523. // TView::GetDrawableQDRect: 
  2524. //----------------------------------------------------------------------------------------
  2525. #pragma segment MAViewRes
  2526.  
  2527. CRect TView::GetDrawableQDRect()
  2528. {
  2529.     CTemporaryRegion drawableRgn;
  2530.  
  2531.     GetDrawableRegion(drawableRgn);
  2532.  
  2533.     return (*(RgnHandle)drawableRgn)->rgnBBox;
  2534. }
  2535.  
  2536. //----------------------------------------------------------------------------------------
  2537. // TView::GetDrawableRegion: 
  2538. //----------------------------------------------------------------------------------------
  2539. #pragma segment MAViewRes
  2540.  
  2541. void TView::GetDrawableRegion(RgnHandle drawRgn)
  2542. {
  2543.     GetVisibleRegion(drawRgn);
  2544.     if (!EmptyRgn(drawRgn))
  2545.         DrawableRgn(drawRgn);
  2546. }
  2547.  
  2548. //----------------------------------------------------------------------------------------
  2549. // TView::GetHelpID: 
  2550. //----------------------------------------------------------------------------------------
  2551. #pragma segment MAViewRes
  2552.  
  2553. ResNumber TView::GetHelpID()
  2554. {
  2555.     return fHelpID;
  2556. }
  2557.  
  2558. //----------------------------------------------------------------------------------------
  2559. // TView::GetHelpIndex: 
  2560. //----------------------------------------------------------------------------------------
  2561. #pragma segment MAViewRes
  2562.  
  2563. short TView::GetHelpIndex()
  2564. {
  2565.     return fHelpIndex;
  2566. }
  2567.  
  2568. //----------------------------------------------------------------------------------------
  2569. // TView::GetHelpState: 
  2570. //----------------------------------------------------------------------------------------
  2571. #pragma segment MAViewRes
  2572.  
  2573. short TView::GetHelpState()
  2574. {
  2575.     return IsEnabled() ? kHMEnabledItem : kHMDisabledItem;
  2576. }
  2577.  
  2578. //----------------------------------------------------------------------------------------
  2579. // TView::GetCursorID: 
  2580. //----------------------------------------------------------------------------------------
  2581. #pragma segment MAViewRes
  2582.  
  2583. ResNumber TView::GetCursorID()
  2584. {
  2585.     return fCursorID;
  2586. }
  2587.  
  2588. //----------------------------------------------------------------------------------------
  2589. // TView::GetHelpParameters: 
  2590. //----------------------------------------------------------------------------------------
  2591. #pragma segment MAViewRes
  2592.  
  2593. void TView::GetHelpParameters(const VPoint& localPoint,
  2594.                               RgnHandle helpRegion,
  2595.                               HMMessageRecord& helpMessage,
  2596.                               CPoint& localQDTip,
  2597.                               CRect& localQDRect,
  2598.                               short& balloonVariant)
  2599. {
  2600.     gDispatcher->GetHelpParameters(GetHelpID(), GetHelpIndex(),// component number within resource
  2601.                                    GetHelpState(),// view state: enabled, disabled etc.
  2602.                                    helpMessage, localQDTip, localQDRect, balloonVariant);
  2603.  
  2604.     // Ignore the hotRect from the resource 
  2605.     if (helpRegion)
  2606.     {
  2607.         localQDRect = (*helpRegion)->rgnBBox;
  2608.         if ((localQDTip.h < 0) || (localQDTip.v < 0))
  2609.         {
  2610.             //GetMouse(localQDTip);     ???
  2611.             localQDTip = ViewToQDPt(localPoint);
  2612.         }
  2613.     }
  2614. }
  2615.  
  2616. //----------------------------------------------------------------------------------------
  2617. // TView::GetRootView: 
  2618. //----------------------------------------------------------------------------------------
  2619. #pragma segment MAViewRes
  2620.  
  2621. TView* TView::GetRootView()
  2622. {
  2623.     return fSuperView ? fSuperView->GetRootView() : this;
  2624. }
  2625.  
  2626. //----------------------------------------------------------------------------------------
  2627. // TView::GetWindow: 
  2628. //----------------------------------------------------------------------------------------
  2629. #pragma segment MAViewRes
  2630.  
  2631. TWindow* TView::GetWindow() const
  2632. {
  2633.     return fSuperView ? fSuperView->GetWindow() : NULL;
  2634. }
  2635.  
  2636. //----------------------------------------------------------------------------------------
  2637. // TView::GivePasteData: 
  2638. //----------------------------------------------------------------------------------------
  2639. #pragma segment MAClipboard
  2640.  
  2641. long TView::GivePasteData(Handle aDataHandle,
  2642.                           ResType dataType)
  2643. {
  2644.     // Make sure the scrap handle is grown out of permanent memory.    If it
  2645.     // was grown out of temporary memory it would eat away at our code space.
  2646.     Boolean savedPerm = PermAllocation(TRUE);
  2647.  
  2648.     long offset;
  2649.     long err = GetScrap(aDataHandle, dataType, &offset);
  2650.  
  2651.     savedPerm = PermAllocation(savedPerm);
  2652.  
  2653. #if qDebugMsg
  2654.     if (err < 0)
  2655.         fprintf(stderr, "TView.GivePasteData got error code # %d from GetScrap for type %s\n", err, (char*) & dataType);
  2656. #endif
  2657.  
  2658.     return err;
  2659. }
  2660.  
  2661. //----------------------------------------------------------------------------------------
  2662. // TView::HandleCursor: 
  2663. //----------------------------------------------------------------------------------------
  2664. #pragma segment MAViewRes
  2665.  
  2666. void TView::HandleCursor(const VPoint& theMouse,
  2667.                          RgnHandle cursorRegion)
  2668. {
  2669.  
  2670.     // Assume if we got here then we already know the mouse is in this view
  2671.     if (LetsSubViewsHandleCursor())
  2672.     {
  2673.         CSubViewIterator iter(this, kIterateBackward);
  2674.  
  2675.         for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  2676.         {
  2677.             VPoint subViewPt(theMouse);
  2678.  
  2679.             theSubView->SuperToLocal(subViewPt);
  2680.             if ((theSubView->ContainsMouse(subViewPt) && theSubView->HandlesCursor()))
  2681.             {
  2682.                 theSubView->HandleCursor(subViewPt, cursorRegion);
  2683.                 // bring the cursor Rgn back to our coordinate system.
  2684.                 theSubView->LocalToSuperRegion(cursorRegion);
  2685.                 break;
  2686.             }
  2687.         }
  2688.     }
  2689.  
  2690.     if (EmptyRgn(cursorRegion) && Focus())
  2691.     {
  2692.         // First let the Behavior have a crack at handling the cursor
  2693.         Boolean proceed = TRUE;
  2694.  
  2695.         GetDefaultCursorRegion(theMouse, cursorRegion);
  2696.  
  2697.         if (GetFirstBehavior())
  2698.             proceed = !((TBehavior *)GetFirstBehavior())->DoSetCursor(theMouse, cursorRegion);
  2699.  
  2700.         if (proceed)
  2701.             DoSetCursor(theMouse, cursorRegion);
  2702.  
  2703.         // Restrict the claimed cursor region to the visible extent of this view
  2704.         RestrictRegionToVisible(cursorRegion);
  2705.     }
  2706. }
  2707.  
  2708. //----------------------------------------------------------------------------------------
  2709. // TView::HandleHelp: 
  2710. //----------------------------------------------------------------------------------------
  2711. #pragma segment MAViewRes
  2712.  
  2713. void TView::HandleHelp(const VPoint& theMouse,
  2714.                        RgnHandle helpRegion)
  2715. {
  2716.     //Assume if we got here then we already know the mouse is in this view
  2717.  
  2718.     if (LetsSubViewsHandleHelp())
  2719.     {
  2720.         CSubViewIterator iter(this, kIterateBackward);
  2721.  
  2722.         for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  2723.         {
  2724.             VPoint subViewPt(theMouse);
  2725.  
  2726.             theSubView->SuperToLocal(subViewPt);
  2727.  
  2728.             if (theSubView->ContainsMouse(subViewPt) && theSubView->HandlesHelp())
  2729.             {
  2730.                 theSubView->HandleHelp(subViewPt, helpRegion);
  2731.  
  2732.                 // bring the help Rgn back to our coordinate system.
  2733.                 theSubView->LocalToSuperRegion(helpRegion);
  2734.                 break;
  2735.             }
  2736.         }
  2737.     }
  2738.  
  2739.     if (EmptyRgn(helpRegion) && HandlesHelp() && Focus())
  2740.     {
  2741.         DoShowHelp(theMouse, helpRegion);
  2742.  
  2743.         // Restrict the claimed help region to the visible extent of this view
  2744.         RestrictRegionToVisible(helpRegion);
  2745.     }
  2746. }
  2747.  
  2748. //----------------------------------------------------------------------------------------
  2749. // TView::HandleMouseDown: 
  2750. //----------------------------------------------------------------------------------------
  2751. #pragma segment MASelCommand
  2752.  
  2753. Boolean TView::HandleMouseDown(const VPoint& theMouse,
  2754.                                TToolboxEvent* event,
  2755.                                CPoint hysteresis,
  2756.                                EMouseDownType mouseDownType)
  2757. {
  2758.     Boolean wasHandled = FALSE;
  2759.  
  2760.     Boolean isFirstClick = (mouseDownType == kFirstClick_dragOnly || mouseDownType == kFirstClick_dragOrClick);
  2761.     Boolean canDoMouse = (mouseDownType == kDragOrClick || mouseDownType == kFirstClick_dragOrClick);
  2762.  
  2763.     if (HasSubViews())
  2764.     {
  2765.         CSubViewIterator iter(this, kIterateBackward);
  2766.  
  2767.         for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  2768.         {
  2769.             VPoint subViewPt = theMouse;
  2770.  
  2771.             theSubView->SuperToLocal(subViewPt);
  2772.             if (theSubView->ContainsMouse(subViewPt))
  2773.                 if (theSubView->HandleMouseDown(subViewPt, event, hysteresis, mouseDownType))
  2774.                 {
  2775.                     wasHandled = TRUE;
  2776.                     break;
  2777.                 }
  2778.         }
  2779.     }
  2780.  
  2781.     if (!wasHandled && Focus())                                // see if we can handle it 
  2782.     {
  2783.         VPoint tempMouse = theMouse;            // We do this so we can pass a const to DoMouseCommand
  2784.         CPoint globalMouse(ViewToQDPt(theMouse));
  2785.         LocalToGlobal(&globalMouse);
  2786.  
  2787.         //  This is important to allowing the cursor to change when selecting
  2788.         if (gDispatcher->IsCursorRgnInvalid())
  2789.         {
  2790.             gDispatcher->TrackCursor(globalMouse);
  2791.             Focus();
  2792.         }
  2793.  
  2794.         if (canDoMouse)
  2795.             UpdateSelection(tempMouse, event);
  2796.  
  2797. #if qDrag
  2798.         // if the user is dragging, and the view wants to drag, initiate a drag
  2799.         if (HasDragManager())
  2800.         {
  2801.             RgnHandle dragCursorRegion = DoMakeDragCursorRegion();
  2802.             if (WillDrag(theMouse, dragCursorRegion))
  2803.             {
  2804.                 dragCursorRegion = DisposeIfRgnHandle(dragCursorRegion);
  2805.                 short cursorID = GetIsDraggingCursorID();
  2806.                 if (cursorID != kNoResource)
  2807.                 {
  2808.                     CursHandle aCursor = GetCursor(cursorID);
  2809.                     FailNILResource((Handle)aCursor);
  2810.                     SetCursor(*aCursor);
  2811.                 }
  2812.                 else
  2813.                     SetCursor(&(qd.arrow));
  2814.  
  2815.                 if (TDragDropSession::fgDragDropSession->UserIsDragging(globalMouse))
  2816.                 {
  2817.                     DoGetDragProxy()->HandleDrag(event);
  2818.                     wasHandled = TRUE;
  2819.                 }
  2820.             }
  2821.             else
  2822.                 dragCursorRegion = DisposeIfRgnHandle(dragCursorRegion);
  2823.         }
  2824. #endif // qDrag
  2825.  
  2826.         if (!wasHandled && isFirstClick)
  2827.         {
  2828.             TWindow * theWindow = GetWindow();
  2829.             if (theWindow != NULL)
  2830.             {
  2831.                 if (!fHandlesFirstClicks)
  2832.                     wasHandled = TRUE;
  2833.                 theWindow->Select();
  2834.                 gDispatcher->UpdateAllWindows();
  2835.                 Focus();
  2836.             }
  2837.         }
  2838.  
  2839.         if (!wasHandled && canDoMouse && IsEnabled())
  2840.         {
  2841.             if (WantsToBeTarget() && !BecomeTarget())
  2842.                 wasHandled = TRUE;                // don't allow subviews to handle it
  2843.             else
  2844.             {
  2845.                 // Give behaviors a chance to handle the mouseDown
  2846.                 TBehavior * aBehavior = GetFirstEnabledBehavior();
  2847.                 if (aBehavior)
  2848.                     wasHandled = aBehavior->DoMouseCommand(tempMouse, event, hysteresis);
  2849.  
  2850.                 if (!wasHandled && IsEnabled())
  2851.                 {
  2852.                     DoMouseCommand(tempMouse, event, hysteresis);
  2853.                     wasHandled = TRUE;
  2854.                 }
  2855.             }
  2856.         }
  2857.  
  2858.         if (wasHandled || GetDraggable())
  2859.             gDispatcher->InvalidateMouseRegions();
  2860.     }
  2861.  
  2862.     return wasHandled;
  2863. }
  2864.  
  2865. //----------------------------------------------------------------------------------------
  2866. // TView::HandleMouseUp: 
  2867. //----------------------------------------------------------------------------------------
  2868. #pragma segment MASelCommand
  2869.  
  2870. Boolean TView::HandleMouseUp(const VPoint& theMouse,
  2871.                              TToolboxEvent* event,
  2872.                              CPoint hysteresis)
  2873. {
  2874.     Boolean wasHandled = FALSE;
  2875.  
  2876.     if (HasSubViews())
  2877.     {
  2878.         CSubViewIterator iter(this, kIterateBackward);
  2879.  
  2880.         for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  2881.         {
  2882.             VPoint subViewPt = theMouse;
  2883.  
  2884.             theSubView->SuperToLocal(subViewPt);
  2885.             if (theSubView->ContainsMouse(subViewPt))
  2886.                 if (theSubView->HandleMouseUp(subViewPt, event, hysteresis))
  2887.                 {
  2888.                     wasHandled = TRUE;
  2889.                     break;
  2890.                 }
  2891.         }
  2892.     }
  2893.  
  2894.     if (!wasHandled && Focus())                                // see if we can handle it 
  2895.     {
  2896.         VPoint tempMouse(theMouse);                // We do this so we can pass a const to DoMouseCommand
  2897.  
  2898.         // Change added to support behaviors
  2899.         Boolean proceed = TRUE;
  2900.  
  2901.         TBehavior * aBehavior = GetFirstEnabledBehavior();
  2902.         if (aBehavior)
  2903.             proceed = !aBehavior->DoMouseUp(tempMouse, event, hysteresis);
  2904.  
  2905.         if (proceed && IsEnabled())
  2906.         {
  2907.             DoMouseUp(tempMouse, event, hysteresis);
  2908.             wasHandled = TRUE;
  2909.         }
  2910.         else
  2911.             wasHandled = !proceed;
  2912.     }
  2913.  
  2914.     return wasHandled;
  2915. }
  2916.  
  2917. //----------------------------------------------------------------------------------------
  2918. // TView::HasPendingUpdate: 
  2919. //----------------------------------------------------------------------------------------
  2920. #pragma segment MAViewRes
  2921.  
  2922. Boolean TView::HasPendingUpdate()
  2923. {
  2924.     return fSuperView ? fSuperView->HasPendingUpdate() : FALSE;
  2925. }
  2926.  
  2927. //----------------------------------------------------------------------------------------
  2928. // TView::InvalidateVRect: 
  2929. //----------------------------------------------------------------------------------------
  2930. #pragma segment MAViewRes
  2931.  
  2932. void TView::InvalidateVRect(const VRect& badVRect)
  2933. {
  2934.     InvalidateRect(ViewToQDRect(badVRect));
  2935. }
  2936.  
  2937. //----------------------------------------------------------------------------------------
  2938. // TView::InvalidateRect: 
  2939. //----------------------------------------------------------------------------------------
  2940. #pragma segment MAViewRes
  2941.  
  2942. void TView::InvalidateRect(const CRect& badRect)
  2943. {
  2944.     CTemporaryRegion badRectRgn;
  2945.  
  2946.     RectRgn(badRectRgn, &badRect);
  2947.     InvalidateRegion(badRectRgn);
  2948. }
  2949.  
  2950. //----------------------------------------------------------------------------------------
  2951. // TView::InvalidateRegion: 
  2952. //----------------------------------------------------------------------------------------
  2953. #pragma segment MAViewRes
  2954.  
  2955. void TView::InvalidateRegion(const RgnHandle badRgn)
  2956. {
  2957.     if (Focus())
  2958.     {
  2959.         CTemporaryRegion visibleBadRgn;
  2960.  
  2961.         RectRgn(visibleBadRgn, &ViewToQDRect(GetVisibleExtent()));
  2962.         SectRgn(badRgn, visibleBadRgn, visibleBadRgn);
  2963.         if (!EmptyRgn(visibleBadRgn))
  2964.             DoInvalidateRegion(visibleBadRgn);
  2965.     }
  2966. }
  2967.  
  2968. //----------------------------------------------------------------------------------------
  2969. // TView::DoInvalidateRegion: 
  2970. //----------------------------------------------------------------------------------------
  2971. #pragma segment MAViewRes
  2972.  
  2973. void TView::DoInvalidateRegion(const RgnHandle badRgn)
  2974. {
  2975.     if (fSuperView)
  2976.         fSuperView->DoInvalidateRegion(badRgn);    // see if someone knows how 
  2977. }
  2978.  
  2979. //----------------------------------------------------------------------------------------
  2980. // TView::IsShown: 
  2981. //----------------------------------------------------------------------------------------
  2982. #pragma segment MAViewRes
  2983.  
  2984. Boolean TView::IsShown()
  2985. {
  2986.     // Rewritten as single exit code. (It's smaller and faster object code too!)
  2987.     Boolean returnVal = fShown;
  2988.  
  2989.     if (!(gDrawingPictScrap && gDrawingPictScrapView == this) && !((TPrintHandler::gCurrPrintHandler != NULL) && (TPrintHandler::gCurrPrintHandler->fView == this)) && fSuperView)
  2990.         returnVal = returnVal && fSuperView->IsShown();// A view can't be shown if its superview isn't shown
  2991.  
  2992.     return returnVal;
  2993. }
  2994.  
  2995. //----------------------------------------------------------------------------------------
  2996. // TView::IsActive: 
  2997. //----------------------------------------------------------------------------------------
  2998. #pragma segment MAViewRes
  2999.  
  3000. Boolean TView::IsActive()
  3001. {
  3002.     return fSuperView ? fSuperView->IsActive() : FALSE;// Can't be "active" without a superview 
  3003. }
  3004.  
  3005. //----------------------------------------------------------------------------------------
  3006. // TView::IsDrawable: 
  3007. //----------------------------------------------------------------------------------------
  3008. #pragma segment MAViewRes
  3009.  
  3010. Boolean TView::IsDrawable()
  3011. {
  3012.     // Rewritten as single exit code. (It's smaller and faster object code too!)
  3013.     // also avoid call to GetDrawableQDRect by checking the clipRgn directly.
  3014.     Boolean returnVal = FALSE;
  3015.  
  3016.     if (IsShown() && Focus())                    // leaves view focused if it is drawable 
  3017.         returnVal = !EmptyRgn(GetClipRegion(qd.thePort));
  3018.  
  3019.     return returnVal;
  3020. }
  3021.  
  3022. //----------------------------------------------------------------------------------------
  3023. // TView::IsVisible: 
  3024. //----------------------------------------------------------------------------------------
  3025. #pragma segment MAViewRes
  3026.  
  3027. Boolean TView::IsVisible()
  3028. {
  3029.     Boolean returnVal = FALSE;
  3030.  
  3031.     if (IsShown())
  3032.         returnVal = IsFocused() ? !GetVisibleQDRect().Empty() : !GetVisibleExtent().Empty();
  3033.  
  3034.     return returnVal;
  3035. }
  3036.  
  3037. //----------------------------------------------------------------------------------------
  3038. // TView::LocalToSuper: 
  3039. //----------------------------------------------------------------------------------------
  3040. #pragma segment MAViewRes
  3041.  
  3042. void TView::LocalToSuper(VPoint& thePoint) const
  3043. {
  3044.     thePoint += GetLocalOffsetInSuper();
  3045. }
  3046.  
  3047. //----------------------------------------------------------------------------------------
  3048. // TView::LocalToSuperVRect: 
  3049. //----------------------------------------------------------------------------------------
  3050. #pragma segment MAViewRes
  3051.  
  3052. void TView::LocalToSuperVRect(VRect& viewRect) const
  3053. {
  3054.     viewRect += GetLocalOffsetInSuper();
  3055. }
  3056.  
  3057. //----------------------------------------------------------------------------------------
  3058. // TView::LocalToSuperRegion: 
  3059. //----------------------------------------------------------------------------------------
  3060. #pragma segment MAViewRes
  3061.  
  3062. void TView::LocalToSuperRegion(RgnHandle theRgn)
  3063. {
  3064.     VPoint localViewPt(QDToViewPt(gZeroPt));    // get 0 in View Space
  3065.     LocalToSuper(localViewPt);
  3066.  
  3067.     CPoint superQDPt(fSuperView ? fSuperView->ViewToQDPt(localViewPt) : localViewPt.ToPoint());
  3068.  
  3069.     OffsetRgn(theRgn, (short)superQDPt.h, (short)superQDPt.v);
  3070. }
  3071.  
  3072.  
  3073. //----------------------------------------------------------------------------------------
  3074. // TView::LocalToWindowRegion: 
  3075. //----------------------------------------------------------------------------------------
  3076. #pragma segment MAViewRes
  3077.  
  3078. void TView::LocalToWindowRegion(RgnHandle theRgn)
  3079. {
  3080.     VPoint localViewPt(QDToViewPt(gZeroPt));    // get 0 in view space
  3081.     LocalToWindow(localViewPt);
  3082.  
  3083.     TWindow * itsWindow = GetWindow();
  3084.     CPoint windowQDPt(itsWindow ? itsWindow->ViewToQDPt(localViewPt) : localViewPt.ToPoint());
  3085.  
  3086.     OffsetRgn(theRgn, (short)windowQDPt.h, (short)windowQDPt.v);
  3087. }
  3088.  
  3089. //----------------------------------------------------------------------------------------
  3090. // TView::LocalToGlobalRegion: 
  3091. //----------------------------------------------------------------------------------------
  3092. #pragma segment MAViewRes
  3093.  
  3094. void TView::LocalToGlobalRegion(RgnHandle theRgn)
  3095. {
  3096.     CPoint globalQDPt(ViewToQDPt(gZeroPt));
  3097.     LocalToGlobal(&globalQDPt);
  3098.  
  3099.     OffsetRgn(theRgn, (short)globalQDPt.h, (short)globalQDPt.v);
  3100. }
  3101.  
  3102. //----------------------------------------------------------------------------------------
  3103. // TView::LocalToWindow: 
  3104. //----------------------------------------------------------------------------------------
  3105. #pragma segment MAViewRes
  3106.  
  3107. void TView::LocalToWindow(VPoint& thePoint) const
  3108. {
  3109.     if (fSuperView)
  3110.     {
  3111.         LocalToSuper(thePoint);
  3112.         fSuperView->LocalToWindow(thePoint);
  3113.     }
  3114. }
  3115.  
  3116. //----------------------------------------------------------------------------------------
  3117. // TView::InvalidateFrameDifference: 
  3118. //----------------------------------------------------------------------------------------
  3119. #pragma segment MAViewNonRes
  3120.  
  3121. void TView::InvalidateFrameDifference(const VRect& oldFrame,
  3122.                                       const VRect& newFrame)
  3123. {
  3124.     if (fSuperView && FocusOnSuperView())
  3125.     {
  3126.         CRect oldQDFrame(fSuperView->ViewToQDRect(oldFrame));
  3127.         CTemporaryRegion oldFrameRgn;
  3128.         RectRgn(oldFrameRgn, &oldQDFrame);
  3129.  
  3130.         CRect newQDFrame(fSuperView->ViewToQDRect(newFrame));
  3131.         CTemporaryRegion newFrameRgn;
  3132.         RectRgn(newFrameRgn, &newQDFrame);
  3133.  
  3134.         // If it didn't move then only the size difference is invalid if the view
  3135.         // doesn't have contents proportional to its size. Otherwise both the regions
  3136.         // are invalid
  3137.         if (oldFrame[topLeft] == newFrame[topLeft])
  3138.             XorRgn(oldFrameRgn, newFrameRgn, newFrameRgn);
  3139.         else
  3140.             UnionRgn(oldFrameRgn, newFrameRgn, newFrameRgn);
  3141.  
  3142.         fSuperView->InvalidateRegion(newFrameRgn);
  3143.     }
  3144. }
  3145.  
  3146. //----------------------------------------------------------------------------------------
  3147. // TView::SetFrame: 
  3148. //----------------------------------------------------------------------------------------
  3149. #pragma segment MAViewNonRes
  3150.  
  3151. void TView::SetFrame(const VRect& newFrame,
  3152.                      Boolean invalidate)
  3153. {
  3154.     VRect oldFrame(GetFrame());
  3155.  
  3156.     if (newFrame != oldFrame)
  3157.     {
  3158.         // update the frame stored in the view
  3159.         fLocation = newFrame[topLeft];
  3160.         fSize = newFrame.GetSize();
  3161.  
  3162.         InvalidateFocus();                        // Must re-focus because frame changed
  3163.         InvalidateCoordinates();                // Re-calc all the offsets
  3164.  
  3165.         gDispatcher->InvalidateMouseRegions();    // Must re-calc cursor and help regions
  3166.  
  3167.         if (invalidate)
  3168.             InvalidateFrameDifference(oldFrame, newFrame);
  3169.  
  3170.         // • Let my adorners know that my frame changed
  3171.         NotifyAdornersOfFrameChange(oldFrame, newFrame, invalidate);
  3172.  
  3173.         // • Let my superview know that my frame changed
  3174.         if (fSuperView)
  3175.             fSuperView->SubViewChangedFrame(this, oldFrame, newFrame, invalidate);
  3176.  
  3177.         // • Let my subviews know that my frame changed
  3178.         NotifySubViewsOfFrameChange(oldFrame, newFrame, invalidate);
  3179.     }
  3180. }
  3181.  
  3182. //----------------------------------------------------------------------------------------
  3183. // TView::NotifyAdornersOfFrameChange: 
  3184. //----------------------------------------------------------------------------------------
  3185. #pragma segment MAViewNonRes
  3186.  
  3187. void TView::NotifyAdornersOfFrameChange(const VRect& oldFrame,
  3188.                                         const VRect& newFrame,
  3189.                                         Boolean invalidate)
  3190. {
  3191.     if (fAdorners && Focus())
  3192.     {
  3193.         CAdornerIterator iter(this);
  3194.  
  3195.         for (TAdorner * anAdorner = iter.FirstAdorner(); iter.More(); anAdorner = iter.NextAdorner())
  3196.             anAdorner->ViewChangedFrame(this, oldFrame, newFrame, invalidate);
  3197.     }
  3198. }
  3199.  
  3200. //----------------------------------------------------------------------------------------
  3201. // TView::NotifySubViewsOfFrameChange: 
  3202. //----------------------------------------------------------------------------------------
  3203. #pragma segment MAViewNonRes
  3204.  
  3205. void TView::NotifySubViewsOfFrameChange(const VRect& oldFrame,
  3206.                                         const VRect& newFrame,
  3207.                                         Boolean invalidate)
  3208. {
  3209.     if (HasSubViews())
  3210.     {
  3211.         CSubViewIterator iter(this);
  3212.  
  3213.         for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  3214.             theSubView->SuperViewChangedFrame(oldFrame, newFrame, invalidate);
  3215.     }
  3216. }
  3217.  
  3218. //----------------------------------------------------------------------------------------
  3219. // TView::Locate: 
  3220. //----------------------------------------------------------------------------------------
  3221. #pragma segment MAViewNonRes
  3222.  
  3223. void TView::Locate(const VPoint& newLoc,
  3224.                    Boolean invalidate)
  3225. {
  3226.     SetFrame(VRect(newLoc, newLoc + fSize), invalidate);
  3227. }
  3228.  
  3229. //----------------------------------------------------------------------------------------
  3230. // TView::MakeFirstSubView: 
  3231. //----------------------------------------------------------------------------------------
  3232. #pragma segment MAViewNonRes
  3233.  
  3234. void TView::MakeFirstSubView(TView* theSubView)
  3235. {
  3236.     DeleteSubView(theSubView);
  3237.     InsertSubView(theSubView, kInsertSubViewFirst);
  3238. }
  3239.  
  3240. //----------------------------------------------------------------------------------------
  3241. // TView::MakeLastSubView: 
  3242. //----------------------------------------------------------------------------------------
  3243. #pragma segment MAViewNonRes
  3244.  
  3245. void TView::MakeLastSubView(TView* theSubView)
  3246. {
  3247.     DeleteSubView(theSubView);
  3248.     InsertSubView(theSubView);
  3249. }
  3250.  
  3251. //----------------------------------------------------------------------------------------
  3252. // TView::Open: 
  3253. //----------------------------------------------------------------------------------------
  3254. #pragma segment MAOpen
  3255.  
  3256. void TView::Open()
  3257. {
  3258.     if (HasSubViews())
  3259.     {
  3260.         CSubViewIterator iter(this);
  3261.  
  3262.         for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  3263.             theSubView->Open();
  3264.     }
  3265. }
  3266.  
  3267. //----------------------------------------------------------------------------------------
  3268. // TView::PageInteriorChanged: 
  3269. //----------------------------------------------------------------------------------------
  3270. #pragma segment MAViewNonRes
  3271.  
  3272. void TView::PageInteriorChanged(const VRect&    /* newInterior */ )
  3273. {
  3274. }
  3275.  
  3276. //----------------------------------------------------------------------------------------
  3277. // TView::RevealUndoRedo:
  3278. //----------------------------------------------------------------------------------------
  3279. #pragma segment MAApplicationRes
  3280.  
  3281. void TView::RevealUndoRedo(TCommand* command)    // override
  3282. {
  3283.     Inherited::RevealUndoRedo(command);
  3284.  
  3285.     SetTargetSelection(kRedraw);
  3286.  
  3287.     TWindow * window = GetWindow();
  3288.     if (window)
  3289.         window->Select();
  3290. }
  3291.  
  3292. //----------------------------------------------------------------------------------------
  3293. // TView::QDToViewPt: 
  3294. //----------------------------------------------------------------------------------------
  3295. #pragma segment MAViewRes
  3296.  
  3297. VPoint TView::QDToViewPt(CPoint qdPoint)
  3298. {
  3299.     return VPoint(qdPoint) + GetViewToQDOffset();
  3300. }
  3301.  
  3302. //----------------------------------------------------------------------------------------
  3303. // TView::QDToViewRect: 
  3304. //----------------------------------------------------------------------------------------
  3305. #pragma segment MAViewRes
  3306.  
  3307. VRect TView::QDToViewRect(const CRect& qdRect)
  3308. {
  3309.     return VRect(qdRect) + GetViewToQDOffset();
  3310. }
  3311.  
  3312. //----------------------------------------------------------------------------------------
  3313. // TView::RemovedASubView: 
  3314. //----------------------------------------------------------------------------------------
  3315. #pragma segment MAViewNonRes
  3316.  
  3317. void TView::RemovedASubView(TView* theSubView)
  3318. {
  3319.     if (fSuperView)
  3320.         fSuperView->RemovedASubView(theSubView);
  3321. }
  3322.  
  3323. //----------------------------------------------------------------------------------------
  3324. // TView::RemoveSubView: 
  3325. //----------------------------------------------------------------------------------------
  3326. #pragma segment MAViewNonRes
  3327.  
  3328. void TView::RemoveSubView(TView* theSubView)
  3329. {
  3330.     DeleteSubView(theSubView);
  3331.  
  3332.     RemovedASubView(theSubView);
  3333.     theSubView->BeInSuperView(NULL);
  3334. }
  3335.  
  3336. //----------------------------------------------------------------------------------------
  3337. // TView::Resize: 
  3338. //----------------------------------------------------------------------------------------
  3339. #pragma segment MAViewNonRes
  3340.  
  3341. void TView::Resize(const VPoint& newSize,
  3342.                    Boolean invalidate)
  3343. {
  3344.     SetFrame(VRect(fLocation, fLocation + newSize), invalidate);
  3345. }
  3346.  
  3347. //----------------------------------------------------------------------------------------
  3348. // TView::RestrictRegionToVisible: 
  3349. //----------------------------------------------------------------------------------------
  3350. #pragma segment MAViewRes
  3351.  
  3352. void TView::RestrictRegionToVisible(RgnHandle aRegion)
  3353. {
  3354. #if qDebug
  3355.     AssumeFocused();
  3356. #endif
  3357.  
  3358.     CRect itsVisibleExtent(ViewToQDRect(GetVisibleExtent()));
  3359.  
  3360.     CTemporaryRegion visibleExtentRgn;
  3361.  
  3362.     RectRgn(visibleExtentRgn, &itsVisibleExtent);
  3363.     SectRgn(aRegion, visibleExtentRgn, aRegion);
  3364.  
  3365.     // Intersect with visible region 
  3366.     SectRgn(TWindow::GetVisRegion(qd.thePort), aRegion, aRegion);
  3367.     SectRgn(GetClipRegion(qd.thePort), aRegion, aRegion);
  3368. }
  3369.  
  3370. //----------------------------------------------------------------------------------------
  3371. // TView::RevealBottom: 
  3372. //----------------------------------------------------------------------------------------
  3373. #pragma segment MAScroll
  3374.  
  3375. void TView::RevealBottom(Boolean redraw)
  3376. {
  3377.     RevealRect(VRect(fSize, fSize), gZeroVPt, redraw);
  3378. }
  3379.  
  3380. //----------------------------------------------------------------------------------------
  3381. // TView::RevealRect: 
  3382. //----------------------------------------------------------------------------------------
  3383. #pragma segment MAScroll
  3384.  
  3385. void TView::RevealRect(const VRect& rectToReveal,
  3386.                        const VPoint& minToSee,
  3387.                        Boolean redraw)
  3388. {
  3389.     if (fSuperView)
  3390.     {
  3391.         VRect localRectToReveal(rectToReveal);
  3392.  
  3393.         LocalToSuperVRect(localRectToReveal);
  3394.         fSuperView->RevealRect(localRectToReveal, minToSee, redraw);
  3395.     }
  3396. }
  3397.  
  3398. //----------------------------------------------------------------------------------------
  3399. // TView::RevealTop: 
  3400. //----------------------------------------------------------------------------------------
  3401. #pragma segment MAScroll
  3402.  
  3403. void TView::RevealTop(Boolean redraw)
  3404. {
  3405.     RevealRect(gZeroVRect, gZeroVPt, redraw);
  3406. }
  3407.  
  3408. //----------------------------------------------------------------------------------------
  3409. // TView::Show: 
  3410. //----------------------------------------------------------------------------------------
  3411. #pragma segment MAViewNonRes
  3412.  
  3413. void TView::Show(Boolean state,
  3414.                  Boolean redraw)
  3415. {
  3416.     if (state != fShown)
  3417.     {
  3418.         if (redraw)
  3419.         {
  3420.             fShown = TRUE;                        // So that ForceRedraw works. 
  3421.             ForceRedraw();
  3422.         }
  3423.         InvalidateFocus();
  3424.         gDispatcher->InvalidateMouseRegions();    // Must re-calc cursor and help regions
  3425.         fShown = state;
  3426.     }
  3427. }
  3428.  
  3429. //----------------------------------------------------------------------------------------
  3430. // TView::ShowReverted: 
  3431. //----------------------------------------------------------------------------------------
  3432. #pragma segment MAReadFile
  3433.  
  3434. void TView::ShowReverted()
  3435. {
  3436.     AdjustFrame();
  3437.     ForceRedraw();
  3438.  
  3439.     if (HasSubViews())
  3440.     {
  3441.         CSubViewIterator iter(this);
  3442.  
  3443.         for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  3444.             theSubView->ShowReverted();
  3445.     }
  3446. }
  3447.  
  3448. //----------------------------------------------------------------------------------------
  3449. // TView::SubViewChangedFrame: 
  3450. //----------------------------------------------------------------------------------------
  3451. #pragma segment MAViewNonRes
  3452.  
  3453. void TView::SubViewChangedFrame(TView*            /* theSubView */ ,
  3454.                                 const VRect&    /* oldFrame */ ,
  3455.                                 const VRect&    /* newFrame */ ,
  3456.                                 Boolean            /* invalidate */)
  3457. {
  3458.     // Just a warning. If you override this method to change your frame based on your
  3459.     // subview changing its frame you will need to be careful if your subviews have size
  3460.     // determiners of sizeRelSuperView. If you do, you will find yourself in an infinite
  3461.     // loop. For an sample solution look at TIncludeView::SubViewChangedFrame. Essentially
  3462.     // you have to be careful not to renotify your subviews that your frame has changed
  3463.     // since you are probably changing your frame because they changed theirs. I think you
  3464.     // get the picture.
  3465. }
  3466.  
  3467. //----------------------------------------------------------------------------------------
  3468. // TView::SuperToLocal: 
  3469. //----------------------------------------------------------------------------------------
  3470. #pragma segment MAViewRes
  3471.  
  3472. void TView::SuperToLocal(VPoint& thePoint) const
  3473. {
  3474.     thePoint -= GetLocalOffsetInSuper();
  3475. }
  3476.  
  3477. //----------------------------------------------------------------------------------------
  3478. // TView::SuperToLocalVRect: 
  3479. //----------------------------------------------------------------------------------------
  3480. #pragma segment MAViewRes
  3481.  
  3482. void TView::SuperToLocalVRect(VRect& viewRect) const
  3483. {
  3484.     viewRect -= GetLocalOffsetInSuper();
  3485. }
  3486.  
  3487. //----------------------------------------------------------------------------------------
  3488. // TView::SuperToLocalRegion: 
  3489. //----------------------------------------------------------------------------------------
  3490. #pragma segment MAViewRes
  3491.  
  3492. void TView::SuperToLocalRegion(RgnHandle theRgn)
  3493. {
  3494.     VPoint localViewPt(QDToViewPt(gZeroPt));    // get 0 in View Space
  3495.     LocalToSuper(localViewPt);
  3496.  
  3497.     CPoint superQDPt(fSuperView ? fSuperView->ViewToQDPt(localViewPt) : localViewPt.ToPoint());
  3498.  
  3499.     OffsetRgn(theRgn, (short) - superQDPt.h, (short) - superQDPt.v);
  3500. }
  3501.  
  3502. //----------------------------------------------------------------------------------------
  3503. // TView::SuperViewChangedFrame: 
  3504. //----------------------------------------------------------------------------------------
  3505. #pragma segment MAViewNonRes
  3506.  
  3507. void TView::SuperViewChangedFrame(const VRect& oldFrame,
  3508.                                   const VRect& newFrame,
  3509.                                   Boolean invalidate)
  3510. {
  3511.     if (oldFrame != newFrame)
  3512.     {
  3513.         VRect itsOldFrame(GetFrame());
  3514.         VRect itsNewFrame(itsOldFrame);
  3515.  
  3516.         for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
  3517.             switch (fSizeDeterminer[vhs])
  3518.             {
  3519.                 case sizeRelSuperView:
  3520.                     // need to capture the amount of change in the superview here for use
  3521.                     // in ComputeFrame
  3522.                     itsNewFrame[botRight][vhs] += newFrame.GetSize()[vhs] - oldFrame.GetSize()[vhs];
  3523.                     break;
  3524.             }
  3525.  
  3526.         ComputeFrame(itsNewFrame);
  3527.         if (itsOldFrame != itsNewFrame)
  3528.         {
  3529.             SetFrame(itsNewFrame, invalidate);
  3530.             DoPagination();
  3531.         }
  3532.     }
  3533. }
  3534.  
  3535. //----------------------------------------------------------------------------------------
  3536. // TView::IsDoneTracking: 
  3537. //----------------------------------------------------------------------------------------
  3538. #pragma segment MADoCommand
  3539.  
  3540. Boolean TView::IsDoneTracking()
  3541. {
  3542.     // Default to mouse-down tracking 
  3543.     return !StillDown();
  3544. }
  3545.  
  3546. //----------------------------------------------------------------------------------------
  3547. // TView::TrackConstrain: 
  3548. //----------------------------------------------------------------------------------------
  3549. #pragma segment MADoCommand
  3550.  
  3551. void TView::TrackConstrain(TrackPhase            /* aTrackPhase */,
  3552.                            const VPoint&        /* anchorPoint */ ,
  3553.                            const VPoint&        /* previousPoint */ ,
  3554.                            VPoint&                /* nextPoint */ ,
  3555.                            Boolean                /* mouseDidMove */)
  3556. {
  3557. }
  3558.  
  3559. //----------------------------------------------------------------------------------------
  3560. // TView::TrackFeedback: 
  3561. //----------------------------------------------------------------------------------------
  3562. #pragma segment MADoCommand
  3563.  
  3564. void TView::TrackFeedback(TrackPhase            /* aTrackPhase */,
  3565.                           const VPoint& anchorPoint,
  3566.                           const VPoint&            /* previousPoint */ ,
  3567.                           const VPoint& nextPoint,
  3568.                           Boolean mouseDidMove,
  3569.                           Boolean                /* turnItOn */)
  3570.  
  3571. // Use code like this to get a flickering rectangle. 
  3572. {
  3573.     if (mouseDidMove)
  3574.     {
  3575.         VRect vr(anchorPoint, nextPoint);
  3576.         vr.Validate();
  3577.  
  3578.         PenPat(&qd.gray);
  3579.         FrameRect(&ViewToQDRect(vr));
  3580.     }
  3581. }
  3582.  
  3583. //----------------------------------------------------------------------------------------
  3584. // TView::TrackMouse: 
  3585. //----------------------------------------------------------------------------------------
  3586. #pragma segment MADoCommand
  3587.  
  3588. void TView::TrackMouse(TrackPhase                /* aTrackPhase */,
  3589.                        VPoint&                    /* anchorPoint */ ,
  3590.                        VPoint&                    /* previousPoint */ ,
  3591.                        VPoint&                    /* nextPoint */ ,
  3592.                        Boolean                    /* mouseDidMove */)
  3593. {
  3594. }
  3595.  
  3596. //----------------------------------------------------------------------------------------
  3597. // TView::Update: 
  3598. //----------------------------------------------------------------------------------------
  3599. #pragma segment MAViewRes
  3600.  
  3601. void TView::Update()
  3602. {
  3603.     if (fSuperView)
  3604.         fSuperView->Update();
  3605.     else
  3606.         DrawContents();
  3607. }
  3608.  
  3609. //----------------------------------------------------------------------------------------
  3610. // TView::GetValidationError: 
  3611. //----------------------------------------------------------------------------------------
  3612. #pragma segment MAViewRes
  3613.  
  3614. long TView::GetValidationError()
  3615. {
  3616.     return noErr;
  3617. }
  3618.  
  3619. //----------------------------------------------------------------------------------------
  3620. // TView::IsValid: 
  3621. //----------------------------------------------------------------------------------------
  3622. #pragma segment MAViewRes
  3623.  
  3624. Boolean TView::IsValid()
  3625. {
  3626.     Boolean returnVal = TRUE;
  3627.  
  3628.     long result = GetValidationError();
  3629.     if (result != noErr)
  3630.     {
  3631.         ValidationFailed(result);
  3632.         returnVal = FALSE;
  3633.     }
  3634.  
  3635.     return returnVal;
  3636. }
  3637.  
  3638. //----------------------------------------------------------------------------------------
  3639. // TView::ValidationFailed: 
  3640. //----------------------------------------------------------------------------------------
  3641. #pragma segment MAViewRes
  3642.  
  3643. void TView::ValidationFailed(long                /* reason */)
  3644. {
  3645. }
  3646.  
  3647. //----------------------------------------------------------------------------------------
  3648. // TView::IsHierarchyValid: 
  3649. //----------------------------------------------------------------------------------------
  3650. #pragma segment MAViewRes
  3651.  
  3652. Boolean TView::IsHierarchyValid()
  3653. {
  3654.     Boolean result = IsValid();
  3655.  
  3656.     if (result && HasSubViews())
  3657.     {
  3658.         CSubViewIterator iter(this);
  3659.  
  3660.         for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  3661.         {
  3662.             result = theSubView->IsHierarchyValid();
  3663.             if (!result)
  3664.                 break;
  3665.         }
  3666.     }
  3667.  
  3668.     return result;
  3669. }
  3670.  
  3671. //----------------------------------------------------------------------------------------
  3672. // TView::ValidateVRect: 
  3673. //----------------------------------------------------------------------------------------
  3674. #pragma segment MAViewRes
  3675.  
  3676. void TView::ValidateVRect(const VRect& goodVRect)
  3677. {
  3678.     ValidateRect(ViewToQDRect(goodVRect));
  3679. }
  3680.  
  3681. //----------------------------------------------------------------------------------------
  3682. // TView::ValidateRect: 
  3683. //----------------------------------------------------------------------------------------
  3684. #pragma segment MAViewRes
  3685.  
  3686. void TView::ValidateRect(const CRect& goodRect)
  3687. {
  3688.     CTemporaryRegion goodRectRgn;
  3689.  
  3690.     RectRgn(goodRectRgn, &goodRect);
  3691.     ValidateRegion(goodRectRgn);
  3692. }
  3693.  
  3694. //----------------------------------------------------------------------------------------
  3695. // TView::ValidateRegion: 
  3696. //----------------------------------------------------------------------------------------
  3697. #pragma segment MAViewRes
  3698.  
  3699. void TView::ValidateRegion(const RgnHandle goodRgn)
  3700. {
  3701.     if (Focus())
  3702.     {
  3703.         CTemporaryRegion visibleGoodRgn;
  3704.  
  3705.         RectRgn(visibleGoodRgn, &ViewToQDRect(GetVisibleExtent()));
  3706.         SectRgn(goodRgn, visibleGoodRgn, visibleGoodRgn);
  3707.         if (!EmptyRgn(visibleGoodRgn))
  3708.             DoValidateRegion(visibleGoodRgn);
  3709.     }
  3710. }
  3711.  
  3712. //----------------------------------------------------------------------------------------
  3713. // TView::DoValidateRegion: 
  3714. //----------------------------------------------------------------------------------------
  3715. #pragma segment MAViewRes
  3716.  
  3717. void TView::DoValidateRegion(const RgnHandle goodRgn)
  3718. {
  3719.     if (fSuperView)
  3720.         fSuperView->DoValidateRegion(goodRgn);    // see if someone knows how 
  3721. }
  3722.  
  3723. //----------------------------------------------------------------------------------------
  3724. // TView::ViewEnable: 
  3725. //----------------------------------------------------------------------------------------
  3726. #pragma segment MAViewRes
  3727.  
  3728. void TView::ViewEnable(Boolean state,
  3729.                        Boolean redraw)
  3730. {
  3731.     SetEnable(state);
  3732.  
  3733.     if (redraw)
  3734.         ForceRedraw();
  3735. }
  3736.  
  3737. //----------------------------------------------------------------------------------------
  3738. // TView::ViewToQDPt: 
  3739. //----------------------------------------------------------------------------------------
  3740. #pragma segment MAViewRes
  3741.  
  3742. CPoint TView::ViewToQDPt(const VPoint& viewPt)
  3743. {
  3744.     return (viewPt - GetViewToQDOffset()).ToPoint();
  3745. }
  3746.  
  3747. //----------------------------------------------------------------------------------------
  3748. // TView::ViewToQDRect: 
  3749. //----------------------------------------------------------------------------------------
  3750. #pragma segment MAViewRes
  3751.  
  3752. CRect TView::ViewToQDRect(const VRect& viewRect)
  3753. {
  3754.     return (viewRect - GetViewToQDOffset()).ToRect();
  3755. }
  3756.  
  3757. //----------------------------------------------------------------------------------------
  3758. // TView::WindowToLocal: 
  3759. //----------------------------------------------------------------------------------------
  3760. #pragma segment MAViewRes
  3761.  
  3762. void TView::WindowToLocal(VPoint& thePoint) const
  3763. {
  3764.     if (fSuperView)
  3765.     {
  3766.         fSuperView->WindowToLocal(thePoint);
  3767.         SuperToLocal(thePoint);
  3768.     }
  3769. }
  3770.  
  3771. //----------------------------------------------------------------------------------------
  3772. // TView::AsPict: 
  3773. //----------------------------------------------------------------------------------------
  3774. #pragma segment MAViewNonRes
  3775.  
  3776. PicHandle TView::AsPict()
  3777. {
  3778.     GrafPort tempPort;
  3779.     CGrafPort tempCPort;
  3780.  
  3781.     MAVolatileInit(GrafPtr, savedPort, GetGrafPort());
  3782.     MAVolatileInit(PicHandle, pHndl, NULL);
  3783.     MAVolatile(Boolean, pictureIsOpen);
  3784.  
  3785.     InvalidateFocus();
  3786.  
  3787.     gDrawingPictScrap = TRUE;
  3788.     gDrawingPictScrapView = this;
  3789.     if (qNeedsColorQD || HasColorQD())
  3790.     {
  3791.         OpenCPort(&tempCPort);
  3792.         BeInPort((GrafPort *) & tempCPort);
  3793.         SetPort((GrafPort *) & tempCPort);
  3794.     }
  3795.     else
  3796.     {
  3797.         OpenPort(&tempPort);
  3798.         BeInPort(&tempPort);
  3799.         SetPort(&tempPort);
  3800.     }
  3801.  
  3802.     FailInfo fi;
  3803.     Try(fi)
  3804.     {
  3805.         if (Focus())
  3806.         {
  3807.             //Open color or black && white, depending on the port
  3808.             CRect qdExtent(GetQDExtent());
  3809.             pHndl = OpenPicture(&qdExtent);
  3810.             pictureIsOpen = TRUE;                // Failure handler needs to close it 
  3811.             FailNIL(pHndl);
  3812.  
  3813.             ClipRect(&qdExtent);
  3814.             DrawContents();
  3815.             ClosePicture();
  3816.             pictureIsOpen = FALSE;                // Failure handler doesn't need to close it 
  3817.  
  3818.             //  On the 128K ROMs the picFrame will be empty if drawing the
  3819.             // picture failed.    On the 64K ROM's QuickDraw simply bombs.
  3820.             if (((CRect &)(*pHndl)->picFrame).Empty())
  3821.             {
  3822. #if qDebug
  3823.                 fprintf(stderr, "Picture frame is empty!\n");
  3824. #endif
  3825.  
  3826.                 FailOSErr(memFullErr);
  3827.             }
  3828.  
  3829.             InvalidateFocus();
  3830.         }
  3831. #if qDebug
  3832.         else                                    // can't focus 
  3833.             ProgramBreak("Can't focus view while writing picture to desk scrap");
  3834. #endif
  3835.  
  3836.         fi.Success();
  3837.     }
  3838.     else                                        // Recover
  3839.     {
  3840.         if (pHndl)
  3841.         {
  3842.             if (pictureIsOpen)
  3843.                 ClosePicture();
  3844.             pHndl = DisposeIfPicHandle(pHndl);
  3845.         }
  3846.  
  3847.         if (qNeedsColorQD || HasColorQD())
  3848.             CloseCPort(&tempCPort);
  3849.         else
  3850.             ClosePort(&tempPort);
  3851.         gDrawingPictScrap = FALSE;
  3852.         gDrawingPictScrapView = NULL;
  3853.         SetPort(savedPort);
  3854.         BeInPort(savedPort);
  3855.         fi.ReSignal();
  3856.     }
  3857.  
  3858.     if (qNeedsColorQD || HasColorQD())
  3859.         CloseCPort(&tempCPort);
  3860.     else
  3861.         ClosePort(&tempPort);
  3862.  
  3863.     gDrawingPictScrap = FALSE;
  3864.     gDrawingPictScrapView = NULL;
  3865.     SetPort(savedPort);
  3866.     BeInPort(savedPort);
  3867.  
  3868.     return pHndl;
  3869. }
  3870.  
  3871. //----------------------------------------------------------------------------------------
  3872. // TView::WriteToDeskScrap: 
  3873. //----------------------------------------------------------------------------------------
  3874. #pragma segment MAClipboard
  3875.  
  3876. void TView::WriteToDeskScrap()
  3877. {
  3878.     MAVolatileInit(PicHandle, pHndl, NULL);
  3879.  
  3880.     FailInfo fi;
  3881.     Try(fi)
  3882.     {
  3883.         pHndl = AsPict();
  3884.         FailNIL(pHndl);
  3885.  
  3886.         FailOSErr(gClipboardMgr->PutDeskScrapData('PICT', (Handle)pHndl));
  3887.  
  3888.         pHndl = DisposeIfPicHandle(pHndl);        // dispose of picture created by AsPict
  3889.         // so failure handler doesn't to kill it 
  3890.         fi.Success();
  3891.     }
  3892.     else                                        // Recover
  3893.     {
  3894.         if (pHndl)
  3895.         {
  3896. #if qDebug
  3897.             ProgramBreak("Failed to put PICT-type scrap");
  3898. #endif
  3899.  
  3900.             pHndl = DisposeIfPicHandle(pHndl);
  3901.         }
  3902.         fi.ReSignal();
  3903.     }
  3904. }
  3905.  
  3906. //----------------------------------------------------------------------------------------
  3907. // TView::GoAwayByUser: 
  3908. //----------------------------------------------------------------------------------------
  3909. #pragma segment MAViewNonRes
  3910.  
  3911. void TView::GoAwayByUser(const VPoint&            /* theMouse */ )
  3912. {
  3913. }
  3914.  
  3915. //----------------------------------------------------------------------------------------
  3916. // TView::MoveByUser: 
  3917. //----------------------------------------------------------------------------------------
  3918. #pragma segment MAViewNonRes
  3919.  
  3920. void TView::MoveByUser(const VPoint&            /* theMouse */ )
  3921. {
  3922. }
  3923.  
  3924. //----------------------------------------------------------------------------------------
  3925. // TView::ResizeByUser: 
  3926. //----------------------------------------------------------------------------------------
  3927. #pragma segment MAViewNonRes
  3928.  
  3929. void TView::ResizeByUser(const VPoint&            /* theMouse */ )
  3930. {
  3931. }
  3932.  
  3933. //----------------------------------------------------------------------------------------
  3934. // TView::SetHLPenState: 
  3935. //----------------------------------------------------------------------------------------
  3936. #pragma segment MAViewNonRes
  3937.  
  3938. void TView::SetHLPenState(HLState fromHL,
  3939.                           HLState toHL)
  3940. {
  3941.     short mode = patXor;                        // every transition except hlOn <-> hlDim uses patXOR
  3942.  
  3943.     PatPtr pPat;
  3944.     if (fromHL + toHL == hlOffOn)
  3945.         pPat = &qd.black;
  3946.     else if (fromHL != toHL)
  3947.         pPat = &qd.gray;
  3948.  
  3949.     if (fromHL + toHL == hlDimOn)
  3950.         mode = notPatXor;
  3951.  
  3952.     PenMode(mode);
  3953.     PenPat(pPat);
  3954. }
  3955.  
  3956. //----------------------------------------------------------------------------------------
  3957. // TView::UpdateCoordinates: 
  3958. //----------------------------------------------------------------------------------------
  3959. #pragma segment MAViewRes
  3960.  
  3961. void TView::UpdateCoordinates()
  3962. {
  3963.     const short kMaxOriginFixup = 1024;            // The maximum amount by which to _fixup_
  3964.     // (not offset) the QD origin when
  3965.     // focusing. This allows patterns and
  3966.     // pixpats to be pinned to global space as
  3967.     // they were intended. See note below.
  3968.     // Larger values than this may be required
  3969.     // for _extremely_ complex pixpats (not
  3970.     // patterns as they are restricted to 8
  3971.     // bit repetition.) The reason that the
  3972.     // fixup is restricted is that you don't
  3973.     // want to run off the end of QD space and
  3974.     // we already have slop allowance of about
  3975.     // 2k in ViewCoords.p.
  3976.  
  3977.     // we can't update our coordinates until our superview updates theirs
  3978.     // however once a views coordinates are valid we don't have to walk up
  3979.     // the tree any further.
  3980.     if (fCoordinatesAreInvalid)
  3981.     {
  3982.         if (fSuperView)
  3983.             fSuperView->UpdateCoordinates();
  3984.  
  3985.         CPoint oldQDOrigin(fQDOrigin);
  3986.         VPoint oldViewToQDOffset(fViewToQDOffset);
  3987.         VRect oldVisibleExtent(fVisibleExtent);
  3988.  
  3989.         if (fSuperView || (TPrintHandler::gCurrPrintHandler && (TPrintHandler::gCurrPrintHandler->fView == this)))
  3990.         {
  3991.             // First calculate and setup the new origins.
  3992.             // But first a word about this approach. (thanks Keith Rollins!) Problems with
  3993.             // pattern alignment when using 32bit views occur when virtual origin of the port
  3994.             // has coordinates that are not multiples of 8. This can occur if, for example,
  3995.             // you scroll a view by increments of other than 8, 16, or other multiple of 8.
  3996.             // The solution is to appropriately set the origin so that patterns are drawn
  3997.             // correctly aligned. This can be done by making sure that we set the origin to
  3998.             // some value that will cause QuickDraw to perform in exactly the same way as if
  3999.             // the origin were really at the value specified by fViewToQDOffset. Since classic
  4000.             // QuickDraw patterns repeat after 8 pixels, we can accomplish this task by making
  4001.             // sure that fViewToQDOffset is a multiple of 8, and setting the origin to
  4002.             // compensate by setting it to fViewToQDOffset % 8.
  4003.             // Unfortunately, this will only work for classic QuickDraw patterns that repeat
  4004.             // after 8 pixels. With PixPats, this period can be any power of 2. In order to
  4005.             // support them, we have to make sure that fViewToQDOffset must be only a multiple
  4006.             // of whatever power of 2 is being used. Ideally, therefore, we could like to make
  4007.             // the chunkiness of fViewToQDOffset to be as large as possible. On the other
  4008.             // hand, we can't make it too large, or else the amount by which we offset the
  4009.             // origin in TView.Focus may overflow QuickDraw's limits. Probably a value of 1024
  4010.             // or 2048 should be sufficient enough to accomodate the largest of PixPats a
  4011.             // developer may use, and still be small enough that we shouldn't overflow
  4012.             // QuickDraw.
  4013.             VPoint localOriginInSuper(GetLocalOffsetInSuper());
  4014.  
  4015.             VPoint actualViewToQDOffset;
  4016.             if (TPrintHandler::gCurrPrintHandler && (TPrintHandler::gCurrPrintHandler->fView == this))
  4017.                 actualViewToQDOffset = TPrintHandler::gCurrPrintHandler->GetViewToQDOffset() + VPoint(TPrintHandler::gCurrPrintHandler->GetQDOrigin());
  4018.             else
  4019.                 actualViewToQDOffset = fSuperView->fViewToQDOffset + VPoint(fSuperView->fQDOrigin) - localOriginInSuper;
  4020.  
  4021.             fViewToQDOffset = actualViewToQDOffset;// to allow testing of the Extent
  4022.             if (VRect(-kMaxCoord, -kMaxCoord, kMaxCoord, kMaxCoord).Contains(GetExtent()))
  4023.             {
  4024.                 fQDOrigin = actualViewToQDOffset.ToPoint();
  4025.                 fViewToQDOffset = gZeroVPt;
  4026.             }
  4027.             else
  4028.             {
  4029.                 CPoint deltaOrigin = CPoint((short)(actualViewToQDOffset.h % kMaxOriginFixup), (short)(actualViewToQDOffset.v % kMaxOriginFixup));
  4030.                 fViewToQDOffset = actualViewToQDOffset - VPoint(deltaOrigin);
  4031.                 fQDOrigin = deltaOrigin;
  4032.             }
  4033.  
  4034.             // Update my visible extent by intersecting my extent with my superview's visible extent
  4035.  
  4036.             // When printing, or drawing the scrap, the grafPort is supplied.
  4037.             if ((gDrawingPictScrapView == this) || ((TPrintHandler::gCurrPrintHandler != NULL) && (TPrintHandler::gCurrPrintHandler->fView == this)))
  4038.                 fVisibleExtent = GetExtent();
  4039.             else
  4040.             {
  4041.                 VRect visibleExtent(GetFrame() & fSuperView->GetVisibleExtent());
  4042.                 SuperToLocalVRect(visibleExtent);
  4043.                 fVisibleExtent = visibleExtent;
  4044.             }
  4045.         }
  4046.         else
  4047.         {
  4048.             fViewToQDOffset = gZeroVPt;
  4049.             fQDOrigin = gZeroPt;
  4050.  
  4051.             fVisibleExtent = GetExtent();
  4052.         }
  4053.  
  4054.         fCoordinatesAreInvalid = FALSE;
  4055.     }
  4056.  
  4057. }
  4058.  
  4059. //----------------------------------------------------------------------------------------
  4060. // TView::InvalidateCoordinates: 
  4061. //----------------------------------------------------------------------------------------
  4062. void TView::InvalidateCoordinates()
  4063. {
  4064.     if (!fCoordinatesAreInvalid)
  4065.     {
  4066.         fCoordinatesAreInvalid = TRUE;
  4067.  
  4068.         CSubViewIterator iter(this);
  4069.  
  4070.         for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  4071.             theSubView->InvalidateCoordinates();
  4072.     }
  4073. }
  4074.  
  4075. //----------------------------------------------------------------------------------------
  4076. // TView::GetVisibleExtent: 
  4077. //----------------------------------------------------------------------------------------
  4078. VRect TView::GetVisibleExtent()
  4079. {
  4080.     if (fCoordinatesAreInvalid)
  4081.         UpdateCoordinates();
  4082.  
  4083.     return fVisibleExtent;
  4084. }
  4085.  
  4086. //----------------------------------------------------------------------------------------
  4087. // TView::GetQDOrigin: 
  4088. //----------------------------------------------------------------------------------------
  4089. CPoint TView::GetQDOrigin()
  4090. {
  4091.     if (fCoordinatesAreInvalid)
  4092.         UpdateCoordinates();
  4093.  
  4094.     return fQDOrigin;
  4095. }
  4096.  
  4097. //----------------------------------------------------------------------------------------
  4098. // TView::GetViewToQDOffset: 
  4099. //----------------------------------------------------------------------------------------
  4100. VPoint TView::GetViewToQDOffset()
  4101. {
  4102.     if (fCoordinatesAreInvalid)
  4103.         UpdateCoordinates();
  4104.  
  4105.     return fViewToQDOffset;
  4106. }
  4107.  
  4108. //----------------------------------------------------------------------------------------
  4109. // TView::ZoomByUser: 
  4110. //----------------------------------------------------------------------------------------
  4111. #pragma segment MAViewNonRes
  4112.  
  4113. void TView::ZoomByUser(const VPoint&            /* theMouse */ ,
  4114.                        short                    /* partCode */)
  4115. {
  4116. }
  4117.  
  4118. //------------------------------------------------------------------------------------
  4119. // Drag and Drop Methods
  4120. //------------------------------------------------------------------------------------
  4121.  
  4122. //----------------------------------------------------------------------------------------
  4123. // TView::SetDroppable: 
  4124. //----------------------------------------------------------------------------------------
  4125. #pragma segment MADragNonRes
  4126.  
  4127. void TView::SetDroppable(Boolean
  4128. #if qDrag
  4129. isDroppable
  4130. #endif
  4131. )
  4132. {
  4133. #if qDrag
  4134.     if (HasDragManager())
  4135.     {
  4136.         TWindow * itsWindow = GetWindow();
  4137.         if (itsWindow != NULL)
  4138.         {
  4139.             if (isDroppable && !fDroppable)
  4140.                 itsWindow->RegisterDroppableView(this);
  4141.             else if (!isDroppable && fDroppable)
  4142.                 itsWindow->UnregisterDroppableView(this);
  4143.         }
  4144.         fDroppable = isDroppable;
  4145.     }
  4146. #endif
  4147. }
  4148.  
  4149. #if qDrag
  4150. //----------------------------------------------------------------------------------------
  4151. // TView::HandleDragCursor: 
  4152. //----------------------------------------------------------------------------------------
  4153. #pragma segment MAViewRes
  4154.  
  4155. void TView::HandleDragCursor(const VPoint& theMouse,
  4156.                              RgnHandle cursorRegion)
  4157. {
  4158.     if (HasSubViews())
  4159.     {
  4160.         CSubViewIterator iter(this, kIterateBackward);
  4161.  
  4162.         for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  4163.         {
  4164.             VPoint subViewPt = theMouse;
  4165.  
  4166.             theSubView->SuperToLocal(subViewPt);
  4167.             if (theSubView->ContainsMouse(subViewPt) && (theSubView->DoGetDragProxy()->GetDraggable() || theSubView->HasSubViews()))
  4168.             {
  4169.                 theSubView->HandleDragCursor(subViewPt, cursorRegion);
  4170.                 // bring the cursor region back to our coordinate system
  4171.                 theSubView->LocalToSuperRegion(cursorRegion);
  4172.                 break;
  4173.             }
  4174.         }
  4175.     }
  4176.  
  4177.     if (EmptyRgn(cursorRegion) && Focus())
  4178.     {
  4179.         GetExtentRegion(cursorRegion);
  4180.  
  4181.         if (HasSubViews())
  4182.         {
  4183.             CTemporaryRegion subViewFrameRgn;
  4184.             CSubViewIterator iter(this);
  4185.  
  4186.             for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  4187.             {
  4188.                 if (theSubView->DoGetDragProxy()->GetDraggable() || theSubView->HasSubViews())
  4189.                 {
  4190.                     theSubView->GetExtentRegion(subViewFrameRgn);
  4191.                     theSubView->LocalToSuperRegion(subViewFrameRgn);
  4192.                     DiffRgn(cursorRegion, subViewFrameRgn, cursorRegion);
  4193.                 }
  4194.             }
  4195.         }
  4196.  
  4197.         RgnHandle dragCursorRegion = NULL;
  4198.         if (!DoSetDragCursor(theMouse, cursorRegion, dragCursorRegion))
  4199.         {
  4200.             if (dragCursorRegion)
  4201.                 DiffRgn(cursorRegion, dragCursorRegion, cursorRegion);
  4202.             SetCursor(&(qd.arrow));
  4203.         }
  4204.  
  4205.         DisposeIfRgnHandle(dragCursorRegion);
  4206.  
  4207.         RestrictRegionToVisible(cursorRegion);
  4208.     }
  4209. }
  4210.  
  4211. //----------------------------------------------------------------------------------------
  4212. // TView::DoSetDragCursor: 
  4213. //----------------------------------------------------------------------------------------
  4214. #pragma segment MAViewRes
  4215.  
  4216. Boolean TView::DoSetDragCursor(const VPoint& localPoint,
  4217.                                RgnHandle cursorRegion,
  4218.                                RgnHandle& dragCursorRegion)
  4219. {
  4220. #if qDebug
  4221.     Assertion(dragCursorRegion == NULL, "\pdragCursorRegion should be NULL");
  4222.     AssumeFocused();
  4223. #endif
  4224.  
  4225.     dragCursorRegion = DoMakeDragCursorRegion();
  4226.     Boolean usingDragCursor = WillDrag(localPoint, dragCursorRegion);
  4227.     if (usingDragCursor)
  4228.     {
  4229.         // cursor region is the intersection of the drag region
  4230.         // and the provided cursor region
  4231.         FailNIL(dragCursorRegion);
  4232.         SectRgn(cursorRegion, dragCursorRegion, cursorRegion);
  4233.         short cursorID = GetWillDragCursorID();
  4234.         if (cursorID != kNoResource)
  4235.         {
  4236.             CursHandle aCursor = GetCursor(cursorID);
  4237.             FailNILResource((Handle)aCursor);
  4238.             SetCursor(*aCursor);
  4239.         }
  4240.         else
  4241.             SetCursor(&(qd.arrow));
  4242.     }
  4243.  
  4244.     return usingDragCursor;
  4245. }
  4246.  
  4247. //----------------------------------------------------------------------------------------
  4248. // TView::GetWillDragCursorID: 
  4249. //----------------------------------------------------------------------------------------
  4250. #pragma segment MADragRes
  4251.  
  4252. short TView::GetWillDragCursorID()
  4253. {
  4254.     return kOpenHandCursor;
  4255. }
  4256.  
  4257. //----------------------------------------------------------------------------------------
  4258. // TView::GetIsDraggingCursorID: 
  4259. //----------------------------------------------------------------------------------------
  4260. #pragma segment MADragNonRes
  4261.  
  4262. short TView::GetIsDraggingCursorID()
  4263. {
  4264.     return kClosedHandCursor;
  4265. }
  4266.  
  4267. //----------------------------------------------------------------------------------------
  4268. // TView::DoMakeDragCursorRegion: 
  4269. //----------------------------------------------------------------------------------------
  4270. #pragma segment MADragRes
  4271.  
  4272. RgnHandle TView::DoMakeDragCursorRegion()
  4273. {
  4274.     RgnHandle dragCursorRegion = NULL;
  4275.  
  4276.     if (GetDraggable())
  4277.         dragCursorRegion = DoMakeDropHiliteRegion();// simple case
  4278.  
  4279.     return dragCursorRegion;
  4280. }
  4281.  
  4282. //----------------------------------------------------------------------------------------
  4283. // TView::WillDrag
  4284. //----------------------------------------------------------------------------------------
  4285. #pragma segment MADragRes
  4286.  
  4287. Boolean TView::WillDrag(const VPoint& localMouse,
  4288.                         const RgnHandle dragCursorRegion)
  4289. {
  4290.     return dragCursorRegion && GetDraggable() ? PtInRgn(ViewToQDPt(localMouse), dragCursorRegion) : FALSE;
  4291. }
  4292.  
  4293. //----------------------------------------------------------------------------------------
  4294. // TView::DoGetDragProxy: 
  4295. //----------------------------------------------------------------------------------------
  4296. #pragma segment MADragRes
  4297.  
  4298. TView* TView::DoGetDragProxy()
  4299. {
  4300.     return this;                                // default is to not provide a proxy
  4301. }
  4302.  
  4303. //----------------------------------------------------------------------------------------
  4304. // TView::HandleDrag: 
  4305. //----------------------------------------------------------------------------------------
  4306. #pragma segment MADragNonRes
  4307.  
  4308. void TView::HandleDrag(TToolboxEvent* event)
  4309. {
  4310.     MAVolatileInit(RgnHandle, dragRegion, NULL);
  4311.  
  4312.     FailInfo fi;
  4313.     Try(fi)
  4314.     {
  4315.         TDragDropSession::fgDragDropSession->ClearDrag();
  4316.         DoAddDragContent();
  4317.         dragRegion = DoMakeDragOutlineRegion();
  4318.         TDragDropSession::fgDragDropSession->StartDrag(this, event, dragRegion);
  4319.         fi.Success();
  4320.     }
  4321.     else                                        // Recover
  4322.     {
  4323.         DisposeIfRgnHandle(dragRegion);
  4324.         fi.ReSignal();
  4325.     }
  4326.  
  4327.     DisposeIfRgnHandle(dragRegion);
  4328. }
  4329.  
  4330. //----------------------------------------------------------------------------------------
  4331. // TView::DoAddDragContent: 
  4332. //----------------------------------------------------------------------------------------
  4333. #pragma segment MANever
  4334.  
  4335. void TView::DoAddDragContent()
  4336. {
  4337.     SubClassResponsibility();
  4338. }
  4339.  
  4340. //----------------------------------------------------------------------------------------
  4341. // TView::DoMakeDragOutlineRegion
  4342. //----------------------------------------------------------------------------------------
  4343. #pragma segment MADragNonRes
  4344.  
  4345. RgnHandle TView::DoMakeDragOutlineRegion()
  4346. {
  4347.     // The drag outline region will usually match the drag cursor region.
  4348.     RgnHandle dragOutlineRegion = DoMakeDragCursorRegion();
  4349.     CTemporaryRegion tempRegion;
  4350.  
  4351.     CopyRgn(dragOutlineRegion, tempRegion);        // make it an outline
  4352.     InsetRgn(tempRegion, 1, 1);
  4353.     DiffRgn(dragOutlineRegion, tempRegion, dragOutlineRegion);
  4354.  
  4355.     LocalToGlobalRegion(dragOutlineRegion);        // globalize
  4356.  
  4357.     return dragOutlineRegion;
  4358. }
  4359.  
  4360. //----------------------------------------------------------------------------------------
  4361. // TView::WillAcceptDrop: 
  4362. //----------------------------------------------------------------------------------------
  4363. #pragma segment MANever
  4364.  
  4365. Boolean TView::WillAcceptDrop(CDragItemIterator&/* dragItemIterator */  )
  4366. {
  4367.     SubClassResponsibility();
  4368.  
  4369.     return FALSE;
  4370. }
  4371.  
  4372. //----------------------------------------------------------------------------------------
  4373. // TView::DoDragEnter: 
  4374. //----------------------------------------------------------------------------------------
  4375. #pragma segment MADragNonRes
  4376.  
  4377. void TView::DoDragEnter()
  4378. {
  4379.     // set up private data used to track drag
  4380. }
  4381.  
  4382. //----------------------------------------------------------------------------------------
  4383. // TView::DoMakeDropHiliteRegion: 
  4384. //----------------------------------------------------------------------------------------
  4385. #pragma segment MADragRes
  4386.  
  4387. RgnHandle TView::DoMakeDropHiliteRegion()
  4388. {
  4389.     RgnHandle dropRegion = MakeNewRgn();
  4390.     RectRgn(dropRegion, &ViewToQDRect(GetVisibleExtent()));
  4391.  
  4392.     return dropRegion;
  4393. }
  4394.  
  4395. //----------------------------------------------------------------------------------------
  4396. // TView::DragWithin: 
  4397. //----------------------------------------------------------------------------------------
  4398. #pragma segment MADragNonRes
  4399.  
  4400. void TView::DoDragWithin(const VPoint&            /*localMouse*/ )
  4401. {
  4402.     // update tracking data and visuals
  4403. }
  4404.  
  4405. //----------------------------------------------------------------------------------------
  4406. // TView::DoDragLeave: 
  4407. //----------------------------------------------------------------------------------------
  4408. #pragma segment MADragNonRes
  4409.  
  4410. void TView::DoDragLeave()
  4411. {
  4412.     // clean up after the drag has left
  4413. }
  4414.  
  4415. //----------------------------------------------------------------------------------------
  4416. // TView::DoMakeDropLocationDescriptor: 
  4417. //----------------------------------------------------------------------------------------
  4418. #pragma segment MADragNonRes
  4419.  
  4420. Boolean TView::DoMakeDropLocationDescriptor(CAEDesc& dropLocationDesc)
  4421. {
  4422.     // Default implementation is to return a description of the containing window.
  4423.     // Subclasses of TView that mix MScriptable object may choose to describe themselves rather
  4424.     // than their containing window.
  4425.     Boolean result = FALSE;
  4426.     TWindow * myWindow = GetWindow();
  4427.  
  4428.     if (myWindow)
  4429.     {
  4430.         FailInfo fi;
  4431.         Try(fi)
  4432.         {
  4433.             result = myWindow->MakeObjectSpecifier(dropLocationDesc, formAbsolutePosition);
  4434.             fi.Success();
  4435.         }
  4436.         // no resignal on failure
  4437.     }
  4438.     return result;
  4439. }
  4440.  
  4441. //----------------------------------------------------------------------------------------
  4442. // TView::WillDragMove: 
  4443. //----------------------------------------------------------------------------------------
  4444. #pragma segment MADragNonRes
  4445.  
  4446. Boolean TView::WillDragMove(TView* destinationView)
  4447. {
  4448.     Boolean isMove;
  4449.  
  4450.     // test the family id's first
  4451.     isMove = (GetDragMoveFamily() == destinationView->GetDragMoveFamily());
  4452.  
  4453.     if (isMove)
  4454.     {
  4455.         switch (GetDragMoveDeterminer())
  4456.         {
  4457.             case kNeverMove:
  4458.                 isMove = FALSE;
  4459.                 break;
  4460.  
  4461.             case kMoveWithinView:
  4462.                 isMove = (this == destinationView);
  4463.                 break;
  4464.  
  4465.             case kMoveWithinWindow:
  4466.                 isMove = (GetWindow() == destinationView->GetWindow());
  4467.                 break;
  4468.  
  4469.             case kMoveWithinContext:
  4470.                 isMove = (GetContext(cDragMove) == destinationView->GetContext(cDragMove));
  4471.                 break;
  4472.  
  4473.             case kMoveWithinApplication:        // already true.
  4474.                 break;
  4475.  
  4476.             default:
  4477.                 isMove = FALSE;                    // unknown context value
  4478.                 break;
  4479.         }
  4480.     }
  4481.  
  4482.     return isMove;
  4483. }
  4484.  
  4485. //----------------------------------------------------------------------------------------
  4486. // TView::DoMakeDragDropCommand:
  4487. //----------------------------------------------------------------------------------------
  4488. #pragma segment MADragNonRes
  4489.  
  4490. TCommand* TView::DoMakeDragDropCommand(CommandNumber/* itsCommandNumber */ ,
  4491.                                        CDragItemIterator&/* dragItemIterator */  )
  4492. {
  4493.     return NULL;                                // subview responsibility
  4494. }
  4495.  
  4496. //----------------------------------------------------------------------------------------
  4497. // TView::DoFulfillPromise: 
  4498. //----------------------------------------------------------------------------------------
  4499. #pragma segment MADragNonRes
  4500.  
  4501. void TView::DoFulfillPromise(TDragItem*            /*promisedItem */ )
  4502. {
  4503.     // subview responsibility
  4504. }
  4505.  
  4506. #endif // qDrag
  4507.  
  4508. //========================================================================================
  4509. // CLASS TIncludeView
  4510. //========================================================================================
  4511. #undef Inherited
  4512. #define Inherited TView
  4513.  
  4514. #pragma segment MAOpen
  4515. MA_DEFINE_CLASS_M1(TIncludeView,
  4516.                    Inherited);
  4517.  
  4518. //----------------------------------------------------------------------------------------
  4519. // TIncludeView constructor.
  4520. //----------------------------------------------------------------------------------------
  4521. #pragma segment MAOpen
  4522.  
  4523. TIncludeView::TIncludeView() :
  4524.     fIncludeRsrcID(kNoResource),
  4525.     fItsSubViewOffset(gZeroVPt),
  4526.     fResourceAttributes(resPurgeable)
  4527. {
  4528.     fEnabled = FALSE;
  4529. }
  4530.  
  4531. //----------------------------------------------------------------------------------------
  4532. // TIncludeView destructor
  4533. //----------------------------------------------------------------------------------------
  4534. #pragma segment MADestructorRes
  4535.  
  4536. TIncludeView::~TIncludeView()
  4537. {
  4538. }
  4539.  
  4540. //----------------------------------------------------------------------------------------
  4541. // TIncludeView::IIncludeView: 
  4542. //----------------------------------------------------------------------------------------
  4543. #pragma segment MAOpen
  4544.  
  4545. void TIncludeView::IIncludeView(TDocument* itsDocument,
  4546.                                 TView* itsSuperView,
  4547.                                 short includeRsrcID,
  4548.                                 const VPoint& itsSubViewOffset,
  4549.                                 const CStr255& resourceName,
  4550.                                 short resourceAttributes)// override 
  4551. {
  4552.     IView(itsDocument, itsSuperView, gZeroVPt, itsSuperView->fSize, sizeSuperView, sizeSuperView);
  4553.  
  4554.     fIncludeRsrcID = includeRsrcID;
  4555.     fItsSubViewOffset = itsSubViewOffset;
  4556.     fResourceName = resourceName;
  4557.     fResourceAttributes = resourceAttributes;
  4558. }
  4559.  
  4560. //----------------------------------------------------------------------------------------
  4561. // TIncludeView::GetStandardSignature: 
  4562. //----------------------------------------------------------------------------------------
  4563. #pragma segment MAWriteResource
  4564.  
  4565. IDType TIncludeView::GetStandardSignature()        // override 
  4566. {
  4567.     return kStdIncludeAt;
  4568. }
  4569.  
  4570. //----------------------------------------------------------------------------------------
  4571. // TIncludeView::DoPostCreate: 
  4572. //----------------------------------------------------------------------------------------
  4573. #pragma segment MAOpen
  4574.  
  4575. void TIncludeView::DoPostCreate(TDocument* itsDocument)// override
  4576. {
  4577.     Inherited::DoPostCreate(itsDocument);
  4578.  
  4579.     TView * aView = NULL;
  4580.  
  4581.     // It only makes sense to do this stuff if we have a view to include.
  4582.     if (fIncludeRsrcID != kNoResource)
  4583.     {
  4584.         if (fSuperView)
  4585.         {
  4586.             // initially, make me "look like" my superview
  4587.             Locate(gZeroVPt, kDontInvalidate);
  4588.             Resize(fSuperView->fSize, kDontInvalidate);
  4589.         }
  4590.  
  4591.         // get the 'View' resource
  4592.         Handle viewResource = GetResource('View', fIncludeRsrcID);
  4593. #if qDebug
  4594.         if (!viewResource)
  4595.         {
  4596.             viewResource = GetResource('view', fIncludeRsrcID);
  4597.             if (viewResource)
  4598.             {
  4599.                 ProgramBreak("Use ViewPromoter. Program contains 2.0 'view' resources");
  4600.                 ReleaseResource(viewResource);
  4601.                 viewResource = NULL;
  4602.             }
  4603.         }
  4604. #endif
  4605.  
  4606.         FailNILResource(viewResource);
  4607.  
  4608.         short theID;
  4609.         ResType theType;
  4610.         GetResInfo(viewResource, &theID, &theType, fResourceName);
  4611.  
  4612.         fResourceAttributes = GetResAttrs(viewResource);
  4613.  
  4614.         // create the included view
  4615.         aView = gViewServer->DoCreateViews(fDocument, this, fIncludeRsrcID, gZeroVPt);
  4616.         FailNIL(aView);
  4617.  
  4618.         // now, make me "look like" my subview
  4619.         fSizeDeterminer[vSel] = aView->fSizeDeterminer[vSel];
  4620.         fSizeDeterminer[hSel] = aView->fSizeDeterminer[hSel];
  4621.         SubViewChangedFrame(aView, gZeroVRect, VRect(fItsSubViewOffset, fItsSubViewOffset + aView->fSize), kDontInvalidate);
  4622.     }
  4623. }
  4624.  
  4625. //----------------------------------------------------------------------------------------
  4626. // TIncludeView::ReadFields: 
  4627. //----------------------------------------------------------------------------------------
  4628. #pragma segment MAReadResource
  4629.  
  4630. void TIncludeView::ReadFields(TStream* aStream)
  4631. {
  4632.     Inherited::ReadFields(aStream);
  4633.  
  4634.     VPoint itsSubViewOffset;
  4635.     FailInfo fi;
  4636.     Try(fi)
  4637.     {
  4638.         fIncludeRsrcID = aStream->ReadInteger();
  4639.  
  4640.         aStream->ReadVPoint(itsSubViewOffset);
  4641.         fItsSubViewOffset = itsSubViewOffset;
  4642.         fi.Success();
  4643.     }
  4644.     else                                        // Recover
  4645.     {
  4646.         Free();
  4647.         fi.ReSignal();
  4648.     }
  4649. }
  4650.  
  4651. //----------------------------------------------------------------------------------------
  4652. // TIncludeView::WriteFields: 
  4653. //----------------------------------------------------------------------------------------
  4654. #pragma segment MAWriteResource
  4655.  
  4656. void TIncludeView::WriteFields(TStream* aStream)
  4657. {
  4658.     Inherited::WriteFields(aStream);
  4659.  
  4660.     aStream->WriteInteger(fIncludeRsrcID);
  4661.  
  4662.     VPoint itsSubViewOffset = fItsSubViewOffset;
  4663.     aStream->WriteVPoint(itsSubViewOffset);
  4664. }
  4665.  
  4666. //----------------------------------------------------------------------------------------
  4667. // TIncludeView::WriteSubViews: 
  4668. //----------------------------------------------------------------------------------------
  4669. #pragma segment MAWriteResource
  4670.  
  4671. void TIncludeView::WriteSubViews(TStream* aStream)
  4672. {
  4673.     // our subviews are "included" and therefore not writeable, so don't call Inherited
  4674.     aStream->WriteInteger(0);                    // write out count of 0 subviews
  4675.  
  4676.     // Call into ViewServer to write out my subview to a 'View' resource with id=fIncludeRsrcID.
  4677. #if qDebugMsg
  4678.     if (CountSubViews() != 1)
  4679.         fprintf(stderr, "TIncludeView::WriteTo only support writing of the first subview.\n");
  4680. #endif
  4681.  
  4682.     if (fIncludeRsrcID != kNoResource)
  4683.     {
  4684.         CStr255 name = fResourceName;
  4685.         gViewServer->WriteViewsToResource(FirstSubView(), fIncludeRsrcID, name, fResourceAttributes);
  4686.     }
  4687. }
  4688.  
  4689. //----------------------------------------------------------------------------------------
  4690. // TIncludeView::SubViewChangedFrame: 
  4691. //----------------------------------------------------------------------------------------
  4692. #pragma segment MAViewNonRes
  4693.  
  4694. void TIncludeView::SubViewChangedFrame(TView* ,
  4695.                                        const VRect& ,
  4696.                                        const VRect& newFrame,
  4697.                                        Boolean invalidate)
  4698. {
  4699.     // Assume that TIncludeView has only 1 subview and that this view should remain the
  4700.     // same size as this one subview. We need to duplicate most of SetFrame here except
  4701.     // that we don't want to renotify our subviews that our frame has changed, especially
  4702.     // if our subview has size determiners of sizeRelSuperView.
  4703.  
  4704.     VRect oldFrame(GetFrame());
  4705.  
  4706.     VRect computedFrame(newFrame);
  4707.     computedFrame += fLocation;                    // offset newFrame by my location
  4708.  
  4709.     if (computedFrame != oldFrame)
  4710.     {
  4711.  
  4712.         // update the frame stored in the view
  4713.         fLocation = computedFrame[topLeft];
  4714.         fSize = computedFrame.GetSize();
  4715.  
  4716.         InvalidateFocus();                        // Must re-focus because frame changed
  4717.         InvalidateCoordinates();                // Re-calc all the offsets
  4718.         gDispatcher->InvalidateMouseRegions();    // Must re-calc cursor and help regions
  4719.  
  4720.         if (invalidate)
  4721.             InvalidateFrameDifference(oldFrame, computedFrame);
  4722.  
  4723.         // • Let my adorners know that my frame changed
  4724.         NotifyAdornersOfFrameChange(oldFrame, computedFrame, invalidate);
  4725.  
  4726.         // • Let my superview know that my frame changed
  4727.         if (fSuperView)
  4728.             fSuperView->SubViewChangedFrame(this, oldFrame, computedFrame, invalidate);
  4729.     }
  4730. }
  4731.  
  4732. //========================================================================================
  4733. // static functions
  4734. //========================================================================================
  4735.  
  4736. //----------------------------------------------------------------------------------------
  4737. // VisibleRect: 
  4738. //----------------------------------------------------------------------------------------
  4739. #pragma segment MAGlobalsRes
  4740.  
  4741. void TView::VisibleRect(CRect& rectToRestrict)
  4742. {
  4743.     CTemporaryRegion rRgn;
  4744.  
  4745.     RectRgn(rRgn, &rectToRestrict);
  4746.     VisibleRgn(rRgn);
  4747.  
  4748.     rectToRestrict = (*(RgnHandle)rRgn)->rgnBBox;
  4749. }
  4750.  
  4751. //----------------------------------------------------------------------------------------
  4752. // DrawableRect: 
  4753. //----------------------------------------------------------------------------------------
  4754. #pragma segment MAGlobalsRes
  4755.  
  4756. void TView::DrawableRect(CRect& rectToRestrict)
  4757. {
  4758.     VisibleRect(rectToRestrict);
  4759.  
  4760.     CTemporaryRegion rRgn;
  4761.  
  4762.     RectRgn(rRgn, &rectToRestrict);
  4763.     DrawableRgn(rRgn);
  4764.  
  4765.     rectToRestrict = (*(RgnHandle)rRgn)->rgnBBox;
  4766. }
  4767.  
  4768. //----------------------------------------------------------------------------------------
  4769. // VisibleRgn: 
  4770. //----------------------------------------------------------------------------------------
  4771. #pragma segment MAGlobalsRes
  4772.  
  4773. void TView::VisibleRgn(RgnHandle rgn)
  4774. {
  4775.     if (!gPrinting && !gDrawingPictScrap)
  4776.         SectRgn(rgn, TWindow::GetVisRegion(qd.thePort), rgn);
  4777. }
  4778.  
  4779. //----------------------------------------------------------------------------------------
  4780. // DrawableRgn: 
  4781. //----------------------------------------------------------------------------------------
  4782. #pragma segment MAGlobalsRes
  4783.  
  4784. void TView::DrawableRgn(RgnHandle rgn)
  4785. {
  4786.     SectRgn(rgn, GetClipRegion(qd.thePort), rgn);
  4787. }
  4788.  
  4789. //----------------------------------------------------------------------------------------
  4790. // PtAndRgn: 
  4791. //----------------------------------------------------------------------------------------
  4792. #pragma segment MAGlobalsRes
  4793.  
  4794. void TView::PtAndRgn(CPoint aPoint,
  4795.                      RgnHandle aRegion)
  4796. {
  4797.     CTemporaryRegion aPointRgn;
  4798.  
  4799.     SetRectRgn(aPointRgn, aPoint.h, aPoint.v, aPoint.h + 1, aPoint.v + 1);
  4800.     UnionRgn(aPointRgn, aRegion, aRegion);
  4801. }
  4802.  
  4803. //----------------------------------------------------------------------------------------
  4804. // VRectAndRgn: 
  4805. //----------------------------------------------------------------------------------------
  4806. #pragma segment MAGlobalsRes
  4807.  
  4808. void TView::VRectAndRgn(const VRect& theVRect,
  4809.                         RgnHandle theRgn)
  4810. {
  4811.     CTemporaryRegion theVRectRgn;
  4812.  
  4813.     RectRgn(theVRectRgn, &theVRect.ToRect());
  4814.     UnionRgn(theVRectRgn, theRgn, theRgn);
  4815. }
  4816.  
  4817. //----------------------------------------------------------------------------------------
  4818. // IsPtVisible: 
  4819. //----------------------------------------------------------------------------------------
  4820. #pragma segment MAViewRes
  4821.  
  4822. Boolean TView::IsPtVisible(CPoint pt)
  4823. {
  4824.     return PtInRgn(pt, TWindow::GetVisRegion(qd.thePort));
  4825. }
  4826.  
  4827. //----------------------------------------------------------------------------------------
  4828. // IsPtDrawable: 
  4829. //----------------------------------------------------------------------------------------
  4830. #pragma segment MAViewRes
  4831.  
  4832. Boolean TView::IsPtDrawable(CPoint pt)
  4833. {
  4834.     return IsPtVisible(pt) && PtInRgn(pt, GetClipRegion(qd.thePort));
  4835. }
  4836.  
  4837. //----------------------------------------------------------------------------------------
  4838. // IsRectVisible: 
  4839. //----------------------------------------------------------------------------------------
  4840. #pragma segment MAViewRes
  4841.  
  4842. Boolean TView::IsRectVisible(const CRect& r)
  4843. {
  4844.     return RectInRgn(&r, TWindow::GetVisRegion(qd.thePort));
  4845. }
  4846.  
  4847. //----------------------------------------------------------------------------------------
  4848. // IsRectDrawable: 
  4849. //----------------------------------------------------------------------------------------
  4850. #pragma segment MAViewRes
  4851.  
  4852. Boolean TView::IsRectDrawable(const CRect& r)
  4853. {
  4854.     return IsRectVisible(r) && RectInRgn(&r, GetClipRegion(qd.thePort));
  4855. }
  4856.  
  4857. //----------------------------------------------------------------------------------------
  4858. // GetFocus: 
  4859. //----------------------------------------------------------------------------------------
  4860. #pragma segment MAViewRes
  4861.  
  4862. void TView::GetFocus(FocusRec& theFocusRec)
  4863. {
  4864.     GetViewPortInfo(theFocusRec.itsViewPortInfo);
  4865.  
  4866.     theFocusRec.focusedView = gFocusedView;
  4867.     theFocusRec.printing = gPrinting;
  4868.     theFocusRec.drawingPictScrap = gDrawingPictScrap;
  4869.     theFocusRec.drawingPictScrapView = gDrawingPictScrapView;
  4870. }
  4871.  
  4872. //----------------------------------------------------------------------------------------
  4873. // SetFocus: 
  4874. //----------------------------------------------------------------------------------------
  4875. #pragma segment MAViewRes
  4876.  
  4877. void TView::SetFocus(const FocusRec& theFocusRec)
  4878. {
  4879.     gFocusedView = theFocusRec.focusedView;
  4880.     gPrinting = theFocusRec.printing;
  4881.     gDrawingPictScrap = theFocusRec.drawingPictScrap;
  4882.     gDrawingPictScrapView = theFocusRec.drawingPictScrapView;
  4883.  
  4884.     SetViewPortInfo(theFocusRec.itsViewPortInfo);
  4885. }
  4886.  
  4887. //----------------------------------------------------------------------------------------
  4888. // GetViewPortInfo: 
  4889. //----------------------------------------------------------------------------------------
  4890. #pragma segment MAViewRes
  4891.  
  4892. void TView::GetViewPortInfo(ViewPortInfo& theViewPortInfo)
  4893. {
  4894.     GetPort(&(theViewPortInfo.port));
  4895.     GetClip(theViewPortInfo.clip);
  4896.     theViewPortInfo.org = ((CRect &)theViewPortInfo.port->portRect)[topLeft];
  4897.     theViewPortInfo.isValid = TRUE;
  4898. }
  4899.  
  4900. //----------------------------------------------------------------------------------------
  4901. // SetViewPortInfo: 
  4902. //----------------------------------------------------------------------------------------
  4903. #pragma segment MAViewRes
  4904.  
  4905. void TView::SetViewPortInfo(const ViewPortInfo& theViewPortInfo)
  4906. {
  4907.     if (qd.thePort != theViewPortInfo.port)        // be nice to accelerator cards 
  4908.         SetPort(theViewPortInfo.port);
  4909.     if (((CRect &)qd.thePort->portRect)[topLeft] != theViewPortInfo.org)
  4910.         SetOrigin(theViewPortInfo.org.h, theViewPortInfo.org.v);
  4911.     SetClip(theViewPortInfo.clip);
  4912. }
  4913.  
  4914. //----------------------------------------------------------------------------------------
  4915. // WriteFocus: 
  4916. //----------------------------------------------------------------------------------------
  4917. #if qDebug
  4918. #pragma segment MADebug
  4919.  
  4920. void TView::WriteFocus()
  4921. {
  4922.     fprintf(stderr, "  fViewToQDOffset = %s\n", (const char*)gFocusedView->fViewToQDOffset);
  4923.     fprintf(stderr, "         portRect = %s\n", (const char*)((CRect &)qd.thePort->portRect));
  4924.     fprintf(stderr, "           visRgn = %s\n", (const char*)((CRect &)(*TWindow::GetVisRegion(qd.thePort))->rgnBBox));
  4925.     fprintf(stderr, "          clipRgn = %s\n", (const char*)((CRect &)(*GetClipRegion(qd.thePort))->rgnBBox));
  4926. }
  4927. #endif
  4928.  
  4929. //----------------------------------------------------------------------------------------
  4930. // GetClipRegion: 
  4931. //----------------------------------------------------------------------------------------
  4932. #pragma segment MAWindowRes
  4933.  
  4934. RgnHandle TView::GetClipRegion(GrafPtr theGrafPtr)
  4935. {
  4936.     return theGrafPtr->clipRgn;
  4937. }
  4938.  
  4939.  
  4940. //----------------------------------------------------------------------------------------
  4941. // TView::InitUView 
  4942. //----------------------------------------------------------------------------------------
  4943. #pragma segment MAViewRes
  4944.  
  4945. void TView::InitUView(Boolean
  4946. #if qGXViews || qGXPrinting
  4947.                       initGX
  4948. #endif
  4949.                       )
  4950. {
  4951. #if qGXViews || qGXPrinting
  4952.     if (initGX && HasQDGXGraphics())
  4953.     {
  4954.         static const long kGXUsegaszRsrc = 0;    // '0' indicates that GX should use the 'gasz' rsrc in your app
  4955.  
  4956.         gGXGraphicsClient = GXNewGraphicsClient(nil, kGXUsegaszRsrc, 0);
  4957.  
  4958.         if (gGXGraphicsClient)
  4959.             GXEnterGraphics();
  4960.     }
  4961. #endif
  4962.  
  4963. }
  4964.  
  4965. //----------------------------------------------------------------------------------------
  4966. // TView::TerminateUView 
  4967. //----------------------------------------------------------------------------------------
  4968. #pragma segment MAViewRes
  4969.  
  4970. void TView::TerminateUView()
  4971. {
  4972. #if qGXViews || qGXPrinting
  4973.     if (gGXGraphicsClient)
  4974.     {
  4975.  
  4976.         GXDisposeGraphicsClient(gGXGraphicsClient);
  4977.         gGXGraphicsClient = NULL;
  4978.  
  4979.         // Only need checking if debugging the application
  4980.         GXExitGraphics();
  4981.     }
  4982. #endif
  4983.  
  4984. }
  4985.  
  4986. //----------------------------------------------------------------------------------------
  4987. // End of UView.cp
  4988.  
  4989. #pragma segment Inline
  4990.  
  4991.